Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1692828lqt; Wed, 20 Mar 2024 11:05:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpybq3+kFXNGjpGIJz9v8JesDrsB2YR719mvasua4/tfzhw43+hyZwEdpVd7metSayGe/0cG/xAIoBj2LfIozqNHluAThEceSTjb0WDw== X-Google-Smtp-Source: AGHT+IGF/oTBz+b7AaIpBZSc0eS2Tyz+sPmB1rM2IJvnztrldwzOeuiuXcRbW57QD/XCkZwAXHNc X-Received: by 2002:a67:ee11:0:b0:476:b556:e4f6 with SMTP id f17-20020a67ee11000000b00476b556e4f6mr2056546vsp.4.1710957911573; Wed, 20 Mar 2024 11:05:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710957911; cv=pass; d=google.com; s=arc-20160816; b=WA2Zgzs223pXvdYlqdi/ZRrinUfG1RlVKhfTxEASom2Iv0KvP+sUhfWblScNh3kSG4 2hzIj+VvGyrDdHlC+D4SmuyOrFczELkLe80Elwa3y9bfoVg5xowl0z162PZsHDiiYKBw cbKeu2WVVJl4k3eDQUTt2xdXfCffNN+xxXe+DuudcX7Axh3p6V7cbWQTiRITa3L3drAa yE3OaDK3mWRQXsEqb0MS3/kUzP3E2weR+2xaWPHcXU/CsVH7nasjU5RB1f4E9BDUPI6r 05wZqE90fzFNCo5yS7oyMhRK1I5a5DNWpjS5Evw7RZgUmQakACv/2hjqSF50IRcm/ing NK4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HCOZaDSQS3uSogr2y2Y4MtomH1kr/Fi4b+AnkoSHYG0=; fh=f2teL0WFTYayu8SJyO372xMpHyk/FlK5te+CZlNr0RY=; b=uRMOoFbeJOrkWItr1YiNcenZ2/OfDcOloWTYkZHsJPIhzE2AYjeLvRWMtZ+a1w7zID rxufsWxXGPuaPPn13SefhTnmvnfUO34+j9JcqzdUifQavaHiKt8NINRYBbRwYUMmnOTd IMiUUom97Sd/Wi8Uok/83f3734gRcpxsUGuOr+EUpNUCKUTJ2Zat719r/tKi+bM5WquN 2CbCoLg0UYn8ZlJFMT9A1iTqqiZXNxVCSKgtySHbnQbF8eeOV/Ujvj1i6+NrRyJahxbK nwBxCYfMFPrsiLFkI1BSef30Bs4MQhpa68kOd2i3dvXO8oa4ombqH+HVfVaD8dbe3ygS xOCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b="0g/90nVD"; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-109276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109276-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l10-20020a67ba0a000000b00470672f1334si1627612vsn.539.2024.03.20.11.05.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 11:05:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b="0g/90nVD"; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-109276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109276-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 00F191C202ED for ; Wed, 20 Mar 2024 18:05:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A087B6BFD0; Wed, 20 Mar 2024 18:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="0g/90nVD" Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F33206A010 for ; Wed, 20 Mar 2024 18:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710957897; cv=none; b=ZgmBIYtw9xjZsnDjuRM6nGgyZf6GEInwwowpFSUUOuOnUuXInK0VcNqBexTnX6Ebc0ojqzGfx/OwahCyPZWDXgOX6KT8IbpST/Pcp1jzVoEGYwqmZgKOfCf5kgTJeibmn51cdn/6yIdpujolm57+/xEFE81YLrWz2cqgW0tP8cw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710957897; c=relaxed/simple; bh=zMKmZdkkzKtk9Q/OCnNBuxwjuv/WnG/o79eAJs14Hq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uwvt+Vxfik5cVa3bjCqDMhCiNFkUhlUIlqAkxRzQ22aU1E9i5gLDv5Y/4xx/Vo/9JIrfxoNTbjfs2PS4YkdYk2TmDUfG0n33xRmPwefJDcTlJZ1o34Ah7YPV2WCMOD94Vjgn8gsdeYkQQZq1j3e9t0IYxFhHrXUE8XyOQnrB9Cc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=0g/90nVD; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-430c4b1a439so936771cf.3 for ; Wed, 20 Mar 2024 11:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1710957894; x=1711562694; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HCOZaDSQS3uSogr2y2Y4MtomH1kr/Fi4b+AnkoSHYG0=; b=0g/90nVDDAWf8MlBvLX9nRCd6KV9Sk2v0FwTBAY4xIp89n+7Yoy3QfjFZ3nkkhtHeO P6eHgNTf1zEzQQBNlwhaEJ01jZicA/1XsisDWfZMgx9AijcKbeqYGvbeFi4GFjZiYcMs EX22Mtw+AHZhwirAdJHlWMrsHd1SlKbtpii/hgjsF+dMpQisPQjgxMYfa4hhyteYTOM+ XsW0owMTP7XaDvvX/7qGdPLoEeMAjiVCM8w5/3gNY0RgFpBy1BIiMfXbBIwmNM8IGShf MOPDYinoZZVqZrxWjcXFSpWfsoP7MyzkQ6mE0OJwQR24oEqOYQQ6Y0M/gvwWdHTg1Hms PMvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710957894; x=1711562694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HCOZaDSQS3uSogr2y2Y4MtomH1kr/Fi4b+AnkoSHYG0=; b=BMWIFtP5OrwZZqzo2yivIFpMIRgCVHV6CSM5CHk72DKeuK+PH04ZNcDqOtVCYXsdFA 90QKdJu+I4UVzBNMQMcnx4IaQPkieobDYdVaRDBM5gzt87UZnFdd9anbh7bk0NbgUPzh oisYreXTQF1k19y31ztayIiTSeaysujMTuFiVfc5dcFGixKFGWJ+idWXtuaam7nyrRCj eGUPx9UQf/8g8d+Yq6thnNm2xVFt1JvWlIiRRZggbdT+hUdLTMQ0iE0KkARhFM7mK/qG FR8lClhre4D6iCzMTM+usz47JEK3pFw61zcJLGelMlukVgxyX8oBiFQZO6Sr7tIUmbYx 13Xg== X-Forwarded-Encrypted: i=1; AJvYcCWAq1RQ2qdCnWvRvGWged49p+11FWyInbhS/Zc+1QUpMnqnbU7Y4/0MQd8VZl5kg4dfai/+7XMHWdCN7cX6N5gn/WrbsQ/NO+nx4y70 X-Gm-Message-State: AOJu0YwJe8A1TlXRwNQzUm0F/XHVRKNuZehWp8vLfdtwojFqh29s/Hul nFRzuY3/9CK6d77edGMt5wlr76VwzM7DBVkPsVN18WRLFBp+ehJG8YjhEUSYA2Y= X-Received: by 2002:a05:622a:54:b0:42f:20f2:c4cf with SMTP id y20-20020a05622a005400b0042f20f2c4cfmr2979645qtw.31.1710957894003; Wed, 20 Mar 2024 11:04:54 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id y17-20020a05622a005100b00430d8e11bebsm3231779qtw.64.2024.03.20.11.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 11:04:53 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Vlastimil Babka , Mel Gorman , Zi Yan , "Huang, Ying" , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/10] mm: page_alloc: optimize free_unref_folios() Date: Wed, 20 Mar 2024 14:02:07 -0400 Message-ID: <20240320180429.678181-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320180429.678181-1-hannes@cmpxchg.org> References: <20240320180429.678181-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move direct freeing of isolated pages to the lock-breaking block in the second loop. This saves an unnecessary migratetype reassessment. Minor comment and local variable scoping cleanups. Suggested-by: Vlastimil Babka Tested-by: "Huang, Ying" Signed-off-by: Johannes Weiner --- mm/page_alloc.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 60a632b7c9f6..994e4f790e92 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2524,7 +2524,7 @@ void free_unref_folios(struct folio_batch *folios) unsigned long __maybe_unused UP_flags; struct per_cpu_pages *pcp = NULL; struct zone *locked_zone = NULL; - int i, j, migratetype; + int i, j; /* Prepare folios for freeing */ for (i = 0, j = 0; i < folios->nr; i++) { @@ -2536,14 +2536,15 @@ void free_unref_folios(struct folio_batch *folios) folio_undo_large_rmappable(folio); if (!free_pages_prepare(&folio->page, order)) continue; - /* - * Free isolated folios and orders not handled on the PCP - * directly to the allocator, see comment in free_unref_page. + * Free orders not handled on the PCP directly to the + * allocator. */ - migratetype = get_pfnblock_migratetype(&folio->page, pfn); - if (!pcp_allowed_order(order) || - is_migrate_isolate(migratetype)) { + if (!pcp_allowed_order(order)) { + int migratetype; + + migratetype = get_pfnblock_migratetype(&folio->page, + pfn); free_one_page(folio_zone(folio), &folio->page, pfn, order, migratetype, FPI_NONE); continue; @@ -2560,15 +2561,29 @@ void free_unref_folios(struct folio_batch *folios) struct zone *zone = folio_zone(folio); unsigned long pfn = folio_pfn(folio); unsigned int order = (unsigned long)folio->private; + int migratetype; folio->private = NULL; migratetype = get_pfnblock_migratetype(&folio->page, pfn); /* Different zone requires a different pcp lock */ - if (zone != locked_zone) { + if (zone != locked_zone || + is_migrate_isolate(migratetype)) { if (pcp) { pcp_spin_unlock(pcp); pcp_trylock_finish(UP_flags); + locked_zone = NULL; + pcp = NULL; + } + + /* + * Free isolated pages directly to the + * allocator, see comment in free_unref_page. + */ + if (is_migrate_isolate(migratetype)) { + free_one_page(zone, &folio->page, pfn, + order, migratetype, FPI_NONE); + continue; } /* @@ -2581,7 +2596,6 @@ void free_unref_folios(struct folio_batch *folios) pcp_trylock_finish(UP_flags); free_one_page(zone, &folio->page, pfn, order, migratetype, FPI_NONE); - locked_zone = NULL; continue; } locked_zone = zone; -- 2.44.0