From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51539C433F5 for ; Mon, 18 Oct 2021 11:47:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 00D0960EE5 for ; Mon, 18 Oct 2021 11:47:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 00D0960EE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C96556B0072; Mon, 18 Oct 2021 07:47:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF8E1900003; Mon, 18 Oct 2021 07:47:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 827D56B0074; Mon, 18 Oct 2021 07:47:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id 6F2456B0072 for ; Mon, 18 Oct 2021 07:47:31 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2D5418249980 for ; Mon, 18 Oct 2021 11:47:31 +0000 (UTC) X-FDA: 78709383102.25.BEC0E32 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by imf06.hostedemail.com (Postfix) with ESMTP id 24417801A89F for ; Mon, 18 Oct 2021 11:47:30 +0000 (UTC) Received: by mail-ed1-f42.google.com with SMTP id y12so71692718eda.4 for ; Mon, 18 Oct 2021 04:47:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GQ9vGBplovxkjkXfQYlY3shu8H3p0LkLkA5L8hbsn4g=; b=1uIepKtMz3dmXeQ7oN4JV58Tc4fnjMX3OJngqluLeSBvXlt6kXkUpYyHRnv7KXrG7d EefZMIDO8aE9m+0pMbK3e6ptO90xwdUMCbvf4ee2GnAjvT5hIr2DblN+112ACcdJHLLh FmRWuwBNKF/WUtaLq+zqoLlxaOo1zUHIoZlIyng/zrazpnz7xkZTmvxAOpFFhFamM9JZ jO2RZpxsHmRSj1zwxjXOel0jM486OccPXN1lY2G7wsv/b+wK+upz63AW5KcR/PIZVZ20 huJA9hTy/f2eqoM8htHosjIc00/FXVFWt9wkklpv51t0PRVzTAylNTyZQ/kCpcuxQ59S LQTg== X-Gm-Message-State: AOAM533wfVD1wEJiMxImxBwc0xnvX/XyqXFES0Z4G6LWuJkwmawXZdEd QHQeqWcMxakbRjmf6zSRPXVLDkgzaYM= X-Google-Smtp-Source: ABdhPJxH7akfI7MYypqxGlSyOwxwmopqyA/cOk5HYHG7CD5PbWSL9XfZKK6k+XVi75CQKzU+7Lvfjw== X-Received: by 2002:a17:906:3c51:: with SMTP id i17mr29943628ejg.86.1634557649682; Mon, 18 Oct 2021 04:47:29 -0700 (PDT) Received: from localhost.localdomain (ip-85-160-35-99.eurotel.cz. [85.160.35.99]) by smtp.gmail.com with ESMTPSA id b2sm9587458edv.73.2021.10.18.04.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 04:47:29 -0700 (PDT) From: Michal Hocko To: Cc: Dave Chinner , Neil Brown , Andrew Morton , Christoph Hellwig , Uladzislau Rezki , , LKML , Ilya Dryomov , Jeff Layton , Michal Hocko Subject: [RFC 3/3] mm: allow !GFP_KERNEL allocations for kvmalloc Date: Mon, 18 Oct 2021 13:47:12 +0200 Message-Id: <20211018114712.9802-4-mhocko@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211018114712.9802-1-mhocko@kernel.org> References: <20211018114712.9802-1-mhocko@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 24417801A89F X-Stat-Signature: ih16oab7diaanhm33rowhhs4tfpuytpp Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of mstsxfx@gmail.com designates 209.85.208.42 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) X-Rspamd-Server: rspam02 X-HE-Tag: 1634557650-47631 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Michal Hocko A support for GFP_NO{FS,IO} and __GFP_NOFAIL has been implemented by previous patches so we can allow the support for kvmalloc. This will allow some external users to simplify or completely remove their helpers. GFP_NOWAIT semantic hasn't been supported so far but it hasn't been explicitly documented so let's add a note about that. ceph_kvmalloc is the first helper to be dropped and changed to kvmalloc. Signed-off-by: Michal Hocko --- include/linux/ceph/libceph.h | 1 - mm/util.c | 15 ++++----------- net/ceph/buffer.c | 4 ++-- net/ceph/ceph_common.c | 27 --------------------------- net/ceph/crypto.c | 2 +- net/ceph/messenger.c | 2 +- net/ceph/messenger_v2.c | 2 +- net/ceph/osdmap.c | 12 ++++++------ 8 files changed, 15 insertions(+), 50 deletions(-) diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h index 409d8c29bc4f..309acbcb5a8a 100644 --- a/include/linux/ceph/libceph.h +++ b/include/linux/ceph/libceph.h @@ -295,7 +295,6 @@ extern bool libceph_compatible(void *data); =20 extern const char *ceph_msg_type_name(int type); extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid = *fsid); -extern void *ceph_kvmalloc(size_t size, gfp_t flags); =20 struct fs_parameter; struct fc_log; diff --git a/mm/util.c b/mm/util.c index bacabe446906..fdec6b4b1267 100644 --- a/mm/util.c +++ b/mm/util.c @@ -549,13 +549,10 @@ EXPORT_SYMBOL(vm_mmap); * Uses kmalloc to get the memory but if the allocation fails then falls= back * to the vmalloc allocator. Use kvfree for freeing the memory. * - * Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported. + * Reclaim modifiers - __GFP_NORETRY and GFP_NOWAIT are not supported. * __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmall= oc is * preferable to the vmalloc fallback, due to visible performance drawba= cks. * - * Please note that any use of gfp flags outside of GFP_KERNEL is carefu= l to not - * fall back to vmalloc. - * * Return: pointer to the allocated memory of %NULL in case of failure */ void *kvmalloc_node(size_t size, gfp_t flags, int node) @@ -563,13 +560,6 @@ void *kvmalloc_node(size_t size, gfp_t flags, int no= de) gfp_t kmalloc_flags =3D flags; void *ret; =20 - /* - * vmalloc uses GFP_KERNEL for some internal allocations (e.g page tabl= es) - * so the given set of flags has to be compatible. - */ - if ((flags & GFP_KERNEL) !=3D GFP_KERNEL) - return kmalloc_node(size, flags, node); - /* * We want to attempt a large physically contiguous block first because * it is less likely to fragment multiple larger blocks and therefore @@ -582,6 +572,9 @@ void *kvmalloc_node(size_t size, gfp_t flags, int nod= e) =20 if (!(kmalloc_flags & __GFP_RETRY_MAYFAIL)) kmalloc_flags |=3D __GFP_NORETRY; + + /* nofail semantic is implemented by the vmalloc fallback */ + kmalloc_flags &=3D ~__GFP_NOFAIL; } =20 ret =3D kmalloc_node(size, kmalloc_flags, node); diff --git a/net/ceph/buffer.c b/net/ceph/buffer.c index 5622763ad402..7e51f128045d 100644 --- a/net/ceph/buffer.c +++ b/net/ceph/buffer.c @@ -7,7 +7,7 @@ =20 #include #include -#include /* for ceph_kvmalloc */ +#include /* for kvmalloc */ =20 struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp) { @@ -17,7 +17,7 @@ struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t g= fp) if (!b) return NULL; =20 - b->vec.iov_base =3D ceph_kvmalloc(len, gfp); + b->vec.iov_base =3D kvmalloc(len, gfp); if (!b->vec.iov_base) { kfree(b); return NULL; diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c index 97d6ea763e32..9441b4a4912b 100644 --- a/net/ceph/ceph_common.c +++ b/net/ceph/ceph_common.c @@ -190,33 +190,6 @@ int ceph_compare_options(struct ceph_options *new_op= t, } EXPORT_SYMBOL(ceph_compare_options); =20 -/* - * kvmalloc() doesn't fall back to the vmalloc allocator unless flags ar= e - * compatible with (a superset of) GFP_KERNEL. This is because while th= e - * actual pages are allocated with the specified flags, the page table p= ages - * are always allocated with GFP_KERNEL. - * - * ceph_kvmalloc() may be called with GFP_KERNEL, GFP_NOFS or GFP_NOIO. - */ -void *ceph_kvmalloc(size_t size, gfp_t flags) -{ - void *p; - - if ((flags & (__GFP_IO | __GFP_FS)) =3D=3D (__GFP_IO | __GFP_FS)) { - p =3D kvmalloc(size, flags); - } else if ((flags & (__GFP_IO | __GFP_FS)) =3D=3D __GFP_IO) { - unsigned int nofs_flag =3D memalloc_nofs_save(); - p =3D kvmalloc(size, GFP_KERNEL); - memalloc_nofs_restore(nofs_flag); - } else { - unsigned int noio_flag =3D memalloc_noio_save(); - p =3D kvmalloc(size, GFP_KERNEL); - memalloc_noio_restore(noio_flag); - } - - return p; -} - static int parse_fsid(const char *str, struct ceph_fsid *fsid) { int i =3D 0; diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c index 92d89b331645..051d22c0e4ad 100644 --- a/net/ceph/crypto.c +++ b/net/ceph/crypto.c @@ -147,7 +147,7 @@ void ceph_crypto_key_destroy(struct ceph_crypto_key *= key) static const u8 *aes_iv =3D (u8 *)CEPH_AES_IV; =20 /* - * Should be used for buffers allocated with ceph_kvmalloc(). + * Should be used for buffers allocated with kvmalloc(). * Currently these are encrypt out-buffer (ceph_buffer) and decrypt * in-buffer (msg front). * diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 57d043b382ed..7b891be799d2 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -1920,7 +1920,7 @@ struct ceph_msg *ceph_msg_new2(int type, int front_= len, int max_data_items, =20 /* front */ if (front_len) { - m->front.iov_base =3D ceph_kvmalloc(front_len, flags); + m->front.iov_base =3D kvmalloc(front_len, flags); if (m->front.iov_base =3D=3D NULL) { dout("ceph_msg_new can't allocate %d bytes\n", front_len); diff --git a/net/ceph/messenger_v2.c b/net/ceph/messenger_v2.c index cc40ce4e02fb..c4099b641b38 100644 --- a/net/ceph/messenger_v2.c +++ b/net/ceph/messenger_v2.c @@ -308,7 +308,7 @@ static void *alloc_conn_buf(struct ceph_connection *c= on, int len) if (WARN_ON(con->v2.conn_buf_cnt >=3D ARRAY_SIZE(con->v2.conn_bufs))) return NULL; =20 - buf =3D ceph_kvmalloc(len, GFP_NOIO); + buf =3D kvmalloc(len, GFP_NOIO); if (!buf) return NULL; =20 diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index 75b738083523..2823bb3cff55 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -980,7 +980,7 @@ static struct crush_work *alloc_workspace(const struc= t crush_map *c) work_size =3D crush_work_size(c, CEPH_PG_MAX_SIZE); dout("%s work_size %zu bytes\n", __func__, work_size); =20 - work =3D ceph_kvmalloc(work_size, GFP_NOIO); + work =3D kvmalloc(work_size, GFP_NOIO); if (!work) return NULL; =20 @@ -1190,9 +1190,9 @@ static int osdmap_set_max_osd(struct ceph_osdmap *m= ap, u32 max) if (max =3D=3D map->max_osd) return 0; =20 - state =3D ceph_kvmalloc(array_size(max, sizeof(*state)), GFP_NOFS); - weight =3D ceph_kvmalloc(array_size(max, sizeof(*weight)), GFP_NOFS); - addr =3D ceph_kvmalloc(array_size(max, sizeof(*addr)), GFP_NOFS); + state =3D kvmalloc(array_size(max, sizeof(*state)), GFP_NOFS); + weight =3D kvmalloc(array_size(max, sizeof(*weight)), GFP_NOFS); + addr =3D kvmalloc(array_size(max, sizeof(*addr)), GFP_NOFS); if (!state || !weight || !addr) { kvfree(state); kvfree(weight); @@ -1222,7 +1222,7 @@ static int osdmap_set_max_osd(struct ceph_osdmap *m= ap, u32 max) if (map->osd_primary_affinity) { u32 *affinity; =20 - affinity =3D ceph_kvmalloc(array_size(max, sizeof(*affinity)), + affinity =3D kvmalloc(array_size(max, sizeof(*affinity)), GFP_NOFS); if (!affinity) return -ENOMEM; @@ -1503,7 +1503,7 @@ static int set_primary_affinity(struct ceph_osdmap = *map, int osd, u32 aff) if (!map->osd_primary_affinity) { int i; =20 - map->osd_primary_affinity =3D ceph_kvmalloc( + map->osd_primary_affinity =3D kvmalloc( array_size(map->max_osd, sizeof(*map->osd_primary_affinity)), GFP_NOFS); if (!map->osd_primary_affinity) --=20 2.30.2