linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/24] Introduce kvfree_rcu(1 or 2 arguments)
@ 2020-04-28 20:58 Uladzislau Rezki (Sony)
  2020-04-28 20:58 ` [PATCH 01/24] rcu/tree: Keep kfree_rcu() awake during lock contention Uladzislau Rezki (Sony)
                   ` (23 more replies)
  0 siblings, 24 replies; 78+ messages in thread
From: Uladzislau Rezki (Sony) @ 2020-04-28 20:58 UTC (permalink / raw)
  To: LKML, linux-mm
  Cc: Andrew Morton, Paul E . McKenney, Theodore Y . Ts'o,
	Matthew Wilcox, Joel Fernandes, RCU, Uladzislau Rezki,
	Oleksiy Avramchenko

Motivation
----------
There were some discussions and demand in having kvfree_rcu()
interface for different purposes. Basically to have a simple
interface like:

<snip>
    void *ptr = kvmalloc(some_bytes, GFP_KERNEL);
        if (ptr)
            kvfree_rcu(ptr);
<snip>

For example, please have a look at ext4 discussion here:
    https://lkml.org/lkml/2020/2/19/1372

due to lack of the interface that is in question, the ext4 specific
workaround has been introduced, to kvfree() after a grace period:

<snip>
void ext4_kvfree_array_rcu(void *to_free)
{
	struct ext4_rcu_ptr *ptr = kzalloc(sizeof(*ptr), GFP_KERNEL);

	if (ptr) {
		ptr->ptr = to_free;
		call_rcu(&ptr->rcu, ext4_rcu_ptr_callback);
		return;
	}
	synchronize_rcu();
	kvfree(ptr);
}
<snip>

there are also similar places there which could be replaced by the new
interface, that is much more efficient then just call synchronize_rcu()
and release a memory.

Please have a look at another places in the kernel where people do not
embed the rcu_head into their stuctures for some reason and do like:

<snip>
    synchronize_rcu();
    kfree(p);
<snip>

<snip>
urezki@pc638:~/data/coding/linux-rcu.git$ find ./ -name "*.c" | xargs grep -C 1 -rn "synchronize_rcu" | grep kfree
./fs/nfs/sysfs.c-113-           kfree(old);
./fs/ext4/super.c-1708- kfree(old_qname);
./kernel/trace/ftrace.c-5079-                   kfree(direct);
./kernel/trace/ftrace.c-5156-                   kfree(direct);
./kernel/trace/trace_probe.c-1087-      kfree(link);
./kernel/module.c-3910- kfree(mod->args);
./net/core/sysctl_net_core.c-143-                               kfree(cur);
./arch/x86/mm/mmio-mod.c-314-           kfree(found_trace);
./drivers/mfd/dln2.c-183-               kfree(i);
./drivers/block/drbd/drbd_state.c-2074-         kfree(old_conf);
./drivers/block/drbd/drbd_nl.c-1689-    kfree(old_disk_conf);
./drivers/block/drbd/drbd_nl.c-2522-    kfree(old_net_conf);
./drivers/block/drbd/drbd_nl.c-2935-            kfree(old_disk_conf);
./drivers/block/drbd/drbd_receiver.c-3805-      kfree(old_net_conf);
./drivers/block/drbd/drbd_receiver.c-4177-                      kfree(old_disk_conf);
./drivers/ipack/carriers/tpci200.c-189- kfree(slot_irq);
./drivers/crypto/nx/nx-842-pseries.c-1010-      kfree(old_devdata);
./drivers/net/ethernet/myricom/myri10ge/myri10ge.c-3583-        kfree(mgp->ss);
./drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c:286:       synchronize_rcu(); /* before kfree(flow) */
./drivers/net/ethernet/mellanox/mlxsw/core.c-1574-      kfree(rxl_item);
./drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c-6642- kfree(adapter->mbox_log);
./drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c-6644- kfree(adapter);
./drivers/infiniband/hw/hfi1/sdma.c-1337-       kfree(dd->per_sdma);
./drivers/infiniband/core/device.c:2164:                         * synchronize_rcu before the netdev is kfreed, so we
./drivers/misc/vmw_vmci/vmci_context.c-692-             kfree(notifier);
./drivers/misc/vmw_vmci/vmci_event.c-213-       kfree(s);
./drivers/staging/fwserial/fwserial.c-2122-     kfree(peer);
urezki@pc638:~/data/coding/linux-rcu.git$
<snip>

so all of it can be replaced by the introduced interface and that
is actually aim and motivation. All that can replaced by the single
kvfree_rcu() logic.

As for double argument of the kvfree_rcu() we have only one user
so far, it is "mm/list_lru.c". But it costs nothing to add it.

Description
-----------
This small series introduces kvfree_rcu() macro that is used
for free memory after a grace period. It can be called either
with one or two arguments. kvfree_rcu() as it derives from its
name can handle two types of pointers, SLAB and vmalloc ones.

As a result we get two ways how to use kvfree_rcu() macro, see
below two examples.

a) kvfree_rcu(ptr, rhf);
    struct X {
        struct rcu_head rhf;
        unsigned char data[100];
    };

    void *ptr = kvmalloc(sizeof(struct X), GFP_KERNEL);
    if (ptr)
        kvfree_rcu(ptr, rhf);

b) kvfree_rcu(ptr);
    void *ptr = kvmalloc(some_bytes, GFP_KERNEL);
    if (ptr)
        kvfree_rcu(ptr);

Last one, we name it headless variant, only needs one argument,
means it does not require any rcu_head to be present within the
type of ptr. There is a restriction the (b) context has to fall
into might_sleep() annotation. To check that, please activate
the CONFIG_DEBUG_ATOMIC_SLEEP option in your kernel.

This series is based on:
git://git.kernel.org/pub/scm/linux/kernel/git/jfern/linux.git
"origin/rcu/dev" branch, what is the same as Paul's almost
latest dev.2020.04.13c branch.

Appreciate for any comments and feedback.

Joel Fernandes (Google) (5):
  rcu/tree: Keep kfree_rcu() awake during lock contention
  rcu/tree: Skip entry into the page allocator for PREEMPT_RT
  rcu/tree: Use consistent style for comments
  rcu/tree: Simplify debug_objects handling
  rcu/tree: Make kvfree_rcu() tolerate any alignment

Sebastian Andrzej Siewior (1):
  rcu/tree: Use static initializer for krc.lock

Uladzislau Rezki (Sony) (18):
  rcu/tree: Repeat the monitor if any free channel is busy
  rcu/tree: Simplify KFREE_BULK_MAX_ENTR macro
  rcu/tree: move locking/unlocking to separate functions
  rcu/tree: cache specified number of objects
  rcu/tree: add rcutree.rcu_min_cached_objs description
  rcu/tree: Maintain separate array for vmalloc ptrs
  rcu/tiny: support vmalloc in tiny-RCU
  rcu: Rename rcu_invoke_kfree_callback/rcu_kfree_callback
  rcu: Rename __is_kfree_rcu_offset() macro
  rcu: Rename kfree_call_rcu() to the kvfree_call_rcu().
  mm/list_lru.c: Rename kvfree_rcu() to local variant
  rcu: Introduce 2 arg kvfree_rcu() interface
  mm/list_lru.c: Remove kvfree_rcu_local() function
  rcu/tree: Support reclaim for head-less object
  rcu/tiny: move kvfree_call_rcu() out of header
  rcu/tiny: support reclaim for head-less object
  rcu: Introduce 1 arg kvfree_rcu() interface
  lib/test_vmalloc.c: Add test cases for kvfree_rcu()

 .../admin-guide/kernel-parameters.txt         |   8 +
 include/linux/rcupdate.h                      |  53 +-
 include/linux/rcutiny.h                       |   6 +-
 include/linux/rcutree.h                       |   2 +-
 include/trace/events/rcu.h                    |   8 +-
 kernel/rcu/tiny.c                             | 168 ++++++-
 kernel/rcu/tree.c                             | 454 +++++++++++++-----
 lib/test_vmalloc.c                            | 103 +++-
 mm/list_lru.c                                 |  11 +-
 9 files changed, 662 insertions(+), 151 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

end of thread, other threads:[~2020-05-07 17:34 UTC | newest]

Thread overview: 78+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 20:58 [PATCH 00/24] Introduce kvfree_rcu(1 or 2 arguments) Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 01/24] rcu/tree: Keep kfree_rcu() awake during lock contention Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 02/24] rcu/tree: Skip entry into the page allocator for PREEMPT_RT Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 03/24] rcu/tree: Use consistent style for comments Uladzislau Rezki (Sony)
2020-05-01 19:05   ` Paul E. McKenney
2020-05-01 20:52     ` Joe Perches
2020-05-03 23:44       ` Joel Fernandes
2020-05-04  0:23         ` Paul E. McKenney
2020-05-04  0:34           ` Joe Perches
2020-05-04  0:41           ` Joel Fernandes
2020-05-03 23:52     ` Joel Fernandes
2020-05-04  0:26       ` Paul E. McKenney
2020-05-04  0:39         ` Joel Fernandes
2020-04-28 20:58 ` [PATCH 04/24] rcu/tree: Repeat the monitor if any free channel is busy Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 05/24] rcu/tree: Simplify debug_objects handling Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 06/24] rcu/tree: Simplify KFREE_BULK_MAX_ENTR macro Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 07/24] rcu/tree: move locking/unlocking to separate functions Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 08/24] rcu/tree: Use static initializer for krc.lock Uladzislau Rezki (Sony)
2020-05-01 21:17   ` Paul E. McKenney
2020-05-04 12:10     ` Uladzislau Rezki
2020-04-28 20:58 ` [PATCH 09/24] rcu/tree: cache specified number of objects Uladzislau Rezki (Sony)
2020-05-01 21:27   ` Paul E. McKenney
2020-05-04 12:43     ` Uladzislau Rezki
2020-05-04 15:24       ` Paul E. McKenney
2020-05-04 17:48         ` Uladzislau Rezki
2020-05-04 18:07           ` Paul E. McKenney
2020-05-04 18:08           ` Joel Fernandes
2020-05-04 19:01             ` Paul E. McKenney
2020-05-04 19:37               ` Joel Fernandes
2020-05-04 19:51                 ` Uladzislau Rezki
2020-05-04 20:15                   ` joel
2020-05-04 20:16                   ` Paul E. McKenney
2020-05-05 11:03                     ` Uladzislau Rezki
2020-04-28 20:58 ` [PATCH 10/24] rcu/tree: add rcutree.rcu_min_cached_objs description Uladzislau Rezki (Sony)
2020-05-01 22:25   ` Paul E. McKenney
2020-05-04 12:44     ` Uladzislau Rezki
2020-04-28 20:58 ` [PATCH 11/24] rcu/tree: Maintain separate array for vmalloc ptrs Uladzislau Rezki (Sony)
2020-05-01 21:37   ` Paul E. McKenney
2020-05-03 23:42     ` Joel Fernandes
2020-05-04  0:20       ` Paul E. McKenney
2020-05-04  0:58         ` Joel Fernandes
2020-05-04  2:20           ` Paul E. McKenney
2020-05-04 14:25     ` Uladzislau Rezki
2020-04-28 20:58 ` [PATCH 12/24] rcu/tiny: support vmalloc in tiny-RCU Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 13/24] rcu: Rename rcu_invoke_kfree_callback/rcu_kfree_callback Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 14/24] rcu: Rename __is_kfree_rcu_offset() macro Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 15/24] rcu: Rename kfree_call_rcu() to the kvfree_call_rcu() Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 16/24] mm/list_lru.c: Rename kvfree_rcu() to local variant Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 17/24] rcu: Introduce 2 arg kvfree_rcu() interface Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 18/24] mm/list_lru.c: Remove kvfree_rcu_local() function Uladzislau Rezki (Sony)
2020-04-28 20:58 ` [PATCH 19/24] rcu/tree: Support reclaim for head-less object Uladzislau Rezki (Sony)
2020-05-01 22:39   ` Paul E. McKenney
2020-05-04  0:12     ` Joel Fernandes
2020-05-04  0:28       ` Paul E. McKenney
2020-05-04  0:32         ` Joel Fernandes
2020-05-04 14:21           ` Uladzislau Rezki
2020-05-04 15:31             ` Paul E. McKenney
2020-05-04 16:56               ` Uladzislau Rezki
2020-05-04 17:08                 ` Paul E. McKenney
2020-05-04 12:57     ` Uladzislau Rezki
2020-04-28 20:58 ` [PATCH 20/24] rcu/tree: Make kvfree_rcu() tolerate any alignment Uladzislau Rezki (Sony)
2020-05-01 23:00   ` Paul E. McKenney
2020-05-04  0:24     ` Joel Fernandes
2020-05-04  0:29       ` Paul E. McKenney
2020-05-04  0:31         ` Joel Fernandes
2020-05-04 12:56           ` Uladzislau Rezki
2020-04-28 20:59 ` [PATCH 21/24] rcu/tiny: move kvfree_call_rcu() out of header Uladzislau Rezki (Sony)
2020-05-01 23:03   ` Paul E. McKenney
2020-05-04 12:45     ` Uladzislau Rezki
2020-05-06 18:29     ` Uladzislau Rezki
2020-05-06 18:45       ` Paul E. McKenney
2020-05-07 17:34         ` Uladzislau Rezki
2020-04-28 20:59 ` [PATCH 22/24] rcu/tiny: support reclaim for head-less object Uladzislau Rezki (Sony)
2020-05-01 23:06   ` Paul E. McKenney
2020-05-04  0:27     ` Joel Fernandes
2020-05-04 12:45       ` Uladzislau Rezki
2020-04-28 20:59 ` [PATCH 23/24] rcu: Introduce 1 arg kvfree_rcu() interface Uladzislau Rezki (Sony)
2020-04-28 20:59 ` [PATCH 24/24] lib/test_vmalloc.c: Add test cases for kvfree_rcu() Uladzislau Rezki (Sony)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).