From patchwork Sat Sep 18 07:15:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12503615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E626C433EF for ; Sat, 18 Sep 2021 07:16:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9A9AE610E9 for ; Sat, 18 Sep 2021 07:16:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9A9AE610E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 349BA6B0071; Sat, 18 Sep 2021 03:16:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AC0A6B0072; Sat, 18 Sep 2021 03:16:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19AD9900002; Sat, 18 Sep 2021 03:16:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 095D16B0071 for ; Sat, 18 Sep 2021 03:16:12 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A9FF7181C9D32 for ; Sat, 18 Sep 2021 07:16:11 +0000 (UTC) X-FDA: 78599835342.13.C71DAC3 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf17.hostedemail.com (Postfix) with ESMTP id 65417F00038D for ; Sat, 18 Sep 2021 07:16:11 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id k24so11873475pgh.8 for ; Sat, 18 Sep 2021 00:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F4eSocmINO9DM/nsnuozs7zFs5+R33uFfLe2OLUBhoI=; b=iiGWy30v0yGnAMDIN+Xw4shv6+BI7AW2yAHxsVxRudefH2vNl3p3ljyHDlXatjh7Kd bGaNOEusZK2e6V4fWzzmK0lcUggJlPQzdbkVh8UDV8cLkZE6NNYT1mk8r5EiNa/mA312 7JNVzbVsAIVpfU+me43YAoy8NOCVcagU9ZHdAKJR2xWkiZ6PV5tYQb6J1WKwsmWwjgN+ jLCO0aImTuPxlLXUwE3wT8U/aD4UaqSYCF+Brq/6SAaMtvH0e8B0OM9txpvbTwzB6VVB 8GAjxDh/c3f8/Niwnzkq7bplo9tDLh0RvwQacDrDBGa4bd9YuYEOeJrIvoQBiNYzX/uJ kkPw== 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:mime-version :content-transfer-encoding; bh=F4eSocmINO9DM/nsnuozs7zFs5+R33uFfLe2OLUBhoI=; b=HMz7bJKQg6M4YShALkQe9BSWM8WuuRwU85Vepe2uJZbRlZTzoWpPhV7d6c1n3weupE yKnSnEulEiHDp8kHNlAuiu9b8Xd/8W2TesQiQoBnC7QQlhDfM9oCc4pMbmHrN0hB2GKs U+PEp9lstOqtsfpUemNs/Rds9g3bvQxQ7NYVcp/nnjc1uvXcLRf7eRthwDE8cGH5vn7Z YaG0yi/ANHC5FjCoBIwCdIw5gsG2EbnSvzBqCFTBmg7ennWD17L0yhDNr+c0FBfPySu9 xpBpFIT72wZ+GxrWGHkTg/ubCU03+SP0yViF1aZ62GPhkzkghmUL26f9maUWfTx4hszx hV7A== X-Gm-Message-State: AOAM5303dmVkb9G/iCubey1SN5UvtT5/EtLVvgzJF/OJ7i3SZS0KFuFs bn2YUQg6SDPRcCPTqOl/dyw= X-Google-Smtp-Source: ABdhPJxLFUrck4i3qspHVH2ydoDCp9EJBR9czP2rN46FQgIVoEn9Ech8WY3FHlVrHhbThEhnGcxaUQ== X-Received: by 2002:a62:15ca:0:b0:43f:76a3:2988 with SMTP id 193-20020a6215ca000000b0043f76a32988mr14934060pfv.65.1631949370198; Sat, 18 Sep 2021 00:16:10 -0700 (PDT) Received: from kvm.asia-northeast3-a.c.our-ratio-313919.internal (252.229.64.34.bc.googleusercontent.com. [34.64.229.252]) by smtp.gmail.com with ESMTPSA id v3sm8080751pfc.193.2021.09.18.00.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Sep 2021 00:16:09 -0700 (PDT) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: 42.hyeyoo@gmail.com Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mm: slub: merge get_freelist into ___slab_alloc Date: Sat, 18 Sep 2021 07:15:51 +0000 Message-Id: <20210918071552.53171-1-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iiGWy30v; spf=pass (imf17.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 65417F00038D X-Stat-Signature: jbwcnwy5i3kbqm73r1ffexr76oh4i77w X-HE-Tag: 1631949371-782783 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: get_freelist was introduced commit 213eeb9fd9d6 ("slub: Extract get_freelist from __slab_alloc") and its comment says this function transfers freelist to the per cpu freelist or deactivate page. But what it actually does is just deactivating page and returning its freelist. And the code working with variable 'new' is confusing because it does nothing. This function have been unmaintained for a long time and is confusing reader. So simplify it for better readability. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slub.c | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 3d2025f7163b..26fe1eb50d88 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2815,40 +2815,6 @@ static inline bool pfmemalloc_match_unsafe(struct page *page, gfp_t gfpflags) return true; } -/* - * Check the page->freelist of a page and either transfer the freelist to the - * per cpu freelist or deactivate the page. - * - * The page is still frozen if the return value is not NULL. - * - * If this function returns NULL then the page has been unfrozen. - */ -static inline void *get_freelist(struct kmem_cache *s, struct page *page) -{ - struct page new; - unsigned long counters; - void *freelist; - - lockdep_assert_held(this_cpu_ptr(&s->cpu_slab->lock)); - - do { - freelist = page->freelist; - counters = page->counters; - - new.counters = counters; - VM_BUG_ON(!new.frozen); - - new.inuse = page->objects; - new.frozen = freelist != NULL; - - } while (!__cmpxchg_double_slab(s, page, - freelist, counters, - NULL, new.counters, - "get_freelist")); - - return freelist; -} - /* * Slow path. The lockless freelist is empty or we need to perform * debugging duties. @@ -2874,6 +2840,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, void *freelist; struct page *page; unsigned long flags; + unsigned long counters; stat(s, ALLOC_SLOWPATH); @@ -2920,12 +2887,21 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, local_unlock_irqrestore(&s->cpu_slab->lock, flags); goto reread_page; } + freelist = c->freelist; if (freelist) goto load_freelist; - freelist = get_freelist(s, page); + /* deactivate page */ + do { + freelist = page->freelist; + counters = page->counters; + } while (!__cmpxchg_double_slab(s, page, + freelist, counters, + NULL, counters, + "deactivate_page")); + /* there was no free objects in that page */ if (!freelist) { c->page = NULL; local_unlock_irqrestore(&s->cpu_slab->lock, flags);