From patchwork Wed Sep 22 15:28:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12510845 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,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 664D4C433EF for ; Wed, 22 Sep 2021 15:28:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 10ACD60F21 for ; Wed, 22 Sep 2021 15:28:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 10ACD60F21 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 49B60900002; Wed, 22 Sep 2021 11:28:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44AD76B0074; Wed, 22 Sep 2021 11:28:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33A09900002; Wed, 22 Sep 2021 11:28:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 25AD76B0073 for ; Wed, 22 Sep 2021 11:28:39 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E0860181AF5FD for ; Wed, 22 Sep 2021 15:28:38 +0000 (UTC) X-FDA: 78615591516.04.19BDA92 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf20.hostedemail.com (Postfix) with ESMTP id A4CDDD0000AD for ; Wed, 22 Sep 2021 15:28:38 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id 17so3046820pgp.4 for ; Wed, 22 Sep 2021 08:28:38 -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=kp0DKxYvjStU9lLWJtLQliS/mXlIIBkYQTnbdZfBCzE=; b=D5TUqu83Rbx8goxjtEUmUrqUWsvsTOIx2eW7pCLs3HhFTKoq8sjupa1Mo/TqMWyPCM YBCATZaRsjXgWQjzPDoDN+e0qHNzLINwjO4LaDBqM+Vmug1fKMb43OsBMIwvq4t+9TY2 GE1l7w8qrpmu3fQCjV1A52r8N6XWz3BbE0Z1TN7neq12Z12RgAwQxyI6LFQVysYe2HvE aV99P+vNQqUfFkZ7DHvM7/nnhwW7ploLm7LP2ZHtHzmCZeYCwIYVXH2ZtV8X63Vkd0nP 1mqfyNEtpJ1grBCSkHFaGKY7VF3AOD/c6scYRq9u1h5++KbMz6bj9qGXd8KzKBgt18Xy b9iQ== 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=kp0DKxYvjStU9lLWJtLQliS/mXlIIBkYQTnbdZfBCzE=; b=1Xfsze5DwO3S1dj1zG7p9Xgw6vSfSk6syVJt2Mu0WQyNKW5qp32J6JjNJo9HdqoVl0 aKL80oOUcM1371edjpgN9+t0RxA3LaugFhzjmKp4cpUFhur63UEd5zkXHDZaMdEBaHo5 tWJUnYFXbKy/HQNVQ2+CnojAwclDCR9Y+GLLLSIEPaIsO62vY1IBRDNCnDJZuXRxynQO Cez2OTr3idR4XyLMXP4v5K0uCHkhe15kmENQZd59LzVXmVTqC1x1EbYw4yPnSfl7cx9n ZvUtTpQ+sGk5CrbOimZYore2AXmLJ47i+4l811UfV9VYol5eZjYW8v3z98jLZTIaHYa6 6krA== X-Gm-Message-State: AOAM530flma59aBBhiJHlAzNzYpBn7E2W5xdcF+lNh90NwamFUyFkvog FtAZcxWZWyliGd5HysPA8t8= X-Google-Smtp-Source: ABdhPJwzBOGmnpoUbHW+VZBWNC4IQ7EVl0xzVd2oXnxyijuXxiB3uZqcUW9/9PFrZ1mrsGCdoxxwjA== X-Received: by 2002:a63:3d8c:: with SMTP id k134mr208828pga.394.1632324517574; Wed, 22 Sep 2021 08:28:37 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:9ca8:a7b7:b32f:a7fb]) by smtp.gmail.com with ESMTPSA id b17sm3178446pgl.61.2021.09.22.08.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 08:28:37 -0700 (PDT) From: Eric Dumazet To: Andrew Morton Cc: linux-kernel , linux-mm , Eric Dumazet , Eric Dumazet , Hugh Dickins Subject: [PATCH] mm: do not acquire zone lock in is_free_buddy_page() Date: Wed, 22 Sep 2021 08:28:33 -0700 Message-Id: <20210922152833.4023972-1-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A4CDDD0000AD X-Stat-Signature: b8g73aw9mp5aduirworrdscgufzs4zci Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=D5TUqu83; spf=pass (imf20.hostedemail.com: domain of eric.dumazet@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=eric.dumazet@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1632324518-595783 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: Eric Dumazet Grabbing zone lock in is_free_buddy_page() gives a wrong sense of safety, and has potential performance implications when zone is experiencing lock contention. In any case, if a caller needs a stable result, it should grab zone lock before calling this function. Signed-off-by: Eric Dumazet Cc: Hugh Dickins Acked-by: Hugh Dickins --- mm/page_alloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e115e21524739341d409b28379942241ed403060..cd8a72372b047e55c4cde80fe6b7a428d7721027 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -9354,21 +9354,21 @@ void __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) } #endif +/* + * This function returns a stable result only if called under zone lock. + */ bool is_free_buddy_page(struct page *page) { - struct zone *zone = page_zone(page); unsigned long pfn = page_to_pfn(page); - unsigned long flags; unsigned int order; - spin_lock_irqsave(&zone->lock, flags); for (order = 0; order < MAX_ORDER; order++) { struct page *page_head = page - (pfn & ((1 << order) - 1)); - if (PageBuddy(page_head) && buddy_order(page_head) >= order) + if (PageBuddy(page_head) && + buddy_order_unsafe(page_head) >= order) break; } - spin_unlock_irqrestore(&zone->lock, flags); return order < MAX_ORDER; }