@@ -95,6 +95,7 @@ torture_param(int, verbose, 1, "Enable verbose debugging printk()s");
9595torture_param (int , writer_holdoff , 0 , "Holdoff (us) between GPs, zero to disable" );
9696torture_param (int , kfree_rcu_test , 0 , "Do we run a kfree_rcu() scale test?" );
9797torture_param (int , kfree_mult , 1 , "Multiple of kfree_obj size to allocate." );
98+ torture_param (int , kfree_by_call_rcu , 0 , "Use call_rcu() to emulate kfree_rcu()?" );
9899
99100static char * scale_type = "rcu" ;
100101module_param (scale_type , charp , 0444 );
@@ -659,6 +660,14 @@ struct kfree_obj {
659660 struct rcu_head rh ;
660661};
661662
663+ /* Used if doing RCU-kfree'ing via call_rcu(). */
664+ static void kfree_call_rcu (struct rcu_head * rh )
665+ {
666+ struct kfree_obj * obj = container_of (rh , struct kfree_obj , rh );
667+
668+ kfree (obj );
669+ }
670+
662671static int
663672kfree_scale_thread (void * arg )
664673{
@@ -696,6 +705,11 @@ kfree_scale_thread(void *arg)
696705 if (!alloc_ptr )
697706 return - ENOMEM ;
698707
708+ if (kfree_by_call_rcu ) {
709+ call_rcu (& (alloc_ptr -> rh ), kfree_call_rcu );
710+ continue ;
711+ }
712+
699713 // By default kfree_rcu_test_single and kfree_rcu_test_double are
700714 // initialized to false. If both have the same value (false or true)
701715 // both are randomly tested, otherwise only the one with value true
@@ -767,11 +781,59 @@ kfree_scale_shutdown(void *arg)
767781 return - EINVAL ;
768782}
769783
784+ // Used if doing RCU-kfree'ing via call_rcu().
785+ static unsigned long jiffies_at_lazy_cb ;
786+ static struct rcu_head lazy_test1_rh ;
787+ static int rcu_lazy_test1_cb_called ;
788+ static void call_rcu_lazy_test1 (struct rcu_head * rh )
789+ {
790+ jiffies_at_lazy_cb = jiffies ;
791+ WRITE_ONCE (rcu_lazy_test1_cb_called , 1 );
792+ }
793+
770794static int __init
771795kfree_scale_init (void )
772796{
773- long i ;
774797 int firsterr = 0 ;
798+ long i ;
799+ unsigned long jif_start ;
800+ unsigned long orig_jif ;
801+
802+ // Also, do a quick self-test to ensure laziness is as much as
803+ // expected.
804+ if (kfree_by_call_rcu && !IS_ENABLED (CONFIG_RCU_LAZY )) {
805+ pr_alert ("CONFIG_RCU_LAZY is disabled, falling back to kfree_rcu() "
806+ "for delayed RCU kfree'ing\n" );
807+ kfree_by_call_rcu = 0 ;
808+ }
809+
810+ if (kfree_by_call_rcu ) {
811+ /* do a test to check the timeout. */
812+ orig_jif = rcu_lazy_get_jiffies_till_flush ();
813+
814+ rcu_lazy_set_jiffies_till_flush (2 * HZ );
815+ rcu_barrier ();
816+
817+ jif_start = jiffies ;
818+ jiffies_at_lazy_cb = 0 ;
819+ call_rcu (& lazy_test1_rh , call_rcu_lazy_test1 );
820+
821+ smp_cond_load_relaxed (& rcu_lazy_test1_cb_called , VAL == 1 );
822+
823+ rcu_lazy_set_jiffies_till_flush (orig_jif );
824+
825+ if (WARN_ON_ONCE (jiffies_at_lazy_cb - jif_start < 2 * HZ )) {
826+ pr_alert ("ERROR: call_rcu() CBs are not being lazy as expected!\n" );
827+ WARN_ON_ONCE (1 );
828+ return -1 ;
829+ }
830+
831+ if (WARN_ON_ONCE (jiffies_at_lazy_cb - jif_start > 3 * HZ )) {
832+ pr_alert ("ERROR: call_rcu() CBs are being too lazy!\n" );
833+ WARN_ON_ONCE (1 );
834+ return -1 ;
835+ }
836+ }
775837
776838 kfree_nrealthreads = compute_real (kfree_nthreads );
777839 /* Start up the kthreads. */
@@ -784,7 +846,9 @@ kfree_scale_init(void)
784846 schedule_timeout_uninterruptible (1 );
785847 }
786848
787- pr_alert ("kfree object size=%zu\n" , kfree_mult * sizeof (struct kfree_obj ));
849+ pr_alert ("kfree object size=%zu, kfree_by_call_rcu=%d\n" ,
850+ kfree_mult * sizeof (struct kfree_obj ),
851+ kfree_by_call_rcu );
788852
789853 kfree_reader_tasks = kcalloc (kfree_nrealthreads , sizeof (kfree_reader_tasks [0 ]),
790854 GFP_KERNEL );
0 commit comments