From patchwork Mon Jan 29 17:54:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13536154 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0686EC47DDB for ; Mon, 29 Jan 2024 17:55:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 917DC6B0074; Mon, 29 Jan 2024 12:55:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6EC6B0075; Mon, 29 Jan 2024 12:55:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 740FC6B0078; Mon, 29 Jan 2024 12:55:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5E61A6B0074 for ; Mon, 29 Jan 2024 12:55:10 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BCC861C066A for ; Mon, 29 Jan 2024 17:55:09 +0000 (UTC) X-FDA: 81733099938.17.39F0414 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf10.hostedemail.com (Postfix) with ESMTP id E2567C0024 for ; Mon, 29 Jan 2024 17:55:07 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FWAzZIbk; spf=pass (imf10.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706550907; a=rsa-sha256; cv=none; b=x4LQPUeIWwsz1jOTzI60v8XDcqXvtPYFBcw4jNzeBvv8nFBleK8a9bpLFJCobIMQFRHd2U TmGwr6yQ7i9M1QGgVJa4ClJ3/Pi6TJKOlSeAPfPufoqOafkSFB0Wu+vYhpHdd0jA70tSdo pupExnjGFNf1+01MFL9E198qNNSiK4I= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FWAzZIbk; spf=pass (imf10.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706550907; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NOwwXIxywhgTYH3p3yq4nMufS2IRUoqO/tf1yKZ7qLU=; b=sfAg8DJZkjgwlGXQk+T6oqEdbrq6kodt8iKzI3pTJDF/xYCYNk418asZ7fTGpBf3H8sujb TGAkGXzkHtWXLVDsBQQpHHnFUudnFa5jTZSbyaeOzOoMBad/dsuWdrqNB5uP5oecxJB64i dMD6v/y3ggs/7CzYgqyijr0Fdq8zudI= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6da6b0eb2d4so1566364b3a.1 for ; Mon, 29 Jan 2024 09:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706550906; x=1707155706; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=NOwwXIxywhgTYH3p3yq4nMufS2IRUoqO/tf1yKZ7qLU=; b=FWAzZIbkdPfLTDSByg9S41kGrSxodmjcAeqekX8feOpl+STbGmQZxfQL4OWuEZHb6Y MHRQKQaADTomF9jQuJiEq485vovItbwUgXEJlI5aZ0rU7H9TdO2s65/vAZxiiYrAimm5 0QEvv+Pr5sKNv1SuUdF+GOuWoT7SLssDoz5rQ0q6THmAg6KO6mbZAC1eTlH5+e1XsDjh vPa8T9mTMG6x1qCml9y2oupboyPUhXz++UECOoxucs/hPlPoi8yLGhUxTce2oGFxILk9 N0heCTQhbI5aQioLvDdkgDRyIisyZB+Z9S/YoI6n/oG8aKtTjYkNTxELz1iY+2DhGAoN idOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706550906; x=1707155706; h=content-transfer-encoding:mime-version:reply-to: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=NOwwXIxywhgTYH3p3yq4nMufS2IRUoqO/tf1yKZ7qLU=; b=Rjw1z5Z+aF2xx8GQqJzz7bvoFPJ4atQ3GQSjxdYsAEQj0uIBu9hVcHv0kKdw7jCLKN htoEwlLlozBDS5Z3V+XcJlCgizwQZauM6VSEFS0r8MkTykZfTgF9bsp1LXdHnk120bQE vPOPD+sDgDv/44pkamVvhn2pl9awkTnvvzTcf3KsTpbC5ILZNQ+AGNzH8XN+u6jEIZVb WLlZ4trjsvAvY0FrgQ7I4jHvkvNgFtqs+fDcF9x+LViYrNY6DUyMc5AQGlcjh4r8+xca CjpxduuBwGJkWfUmQmpGkhM7Gpo+/nYpDCKYyvpckU0SuRi21WmPPZK7JTi/L1B5/XBZ NqoQ== X-Gm-Message-State: AOJu0YyVL/5xHWwiVhxe30pO7vhwaNjwFcGbyXnoXunKDAEgJTX2usGP J7kWoOi0wf+9cHhoniRHvSuQ4BmcaA0RsbID8H38ThKtiuktbV3slmGs0xzFLbTMhA== X-Google-Smtp-Source: AGHT+IHcsxUcn8preTc9iTpcswRaxjzdS4S22LBey4Xk5lFq3gP76HzVu0IIMkVly7esBhMrp+Y1Kw== X-Received: by 2002:aa7:8a13:0:b0:6db:e14f:3956 with SMTP id m19-20020aa78a13000000b006dbe14f3956mr2218904pfa.20.1706550906055; Mon, 29 Jan 2024 09:55:06 -0800 (PST) Received: from KASONG-MB2.tencent.com ([1.203.117.98]) by smtp.gmail.com with ESMTPSA id h8-20020aa79f48000000b006ddcadb1e2csm6116676pfr.29.2024.01.29.09.55.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Jan 2024 09:55:05 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , "Huang, Ying" , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v3 1/7] mm/swapfile.c: add back some comment Date: Tue, 30 Jan 2024 01:54:16 +0800 Message-ID: <20240129175423.1987-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129175423.1987-1-ryncsn@gmail.com> References: <20240129175423.1987-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E2567C0024 X-Stat-Signature: k1yx5gnim7kdfgfsjnzx7zyy1hamzsyy X-Rspam-User: X-HE-Tag: 1706550907-699957 X-HE-Meta: U2FsdGVkX1+KVK11fi7bbS93O7Eqk2I3d9P1PDbYtOd8ps/Wvbllb6rFXHR2ezxDG9xGImBSoeb93sKcaYo33ENjUwGd1PyiAzL9XVIMugBAvY6QMMRNB5JYkRbF5Ami2a+gSnTqT3t/GsNH31THWiEndHltvNbFMkViNM8/AC6WU6XkxPNhfl8k2wusjsnFTMVXHrQ/h83k1q1xQnzQ/Z8Fln2s9lu2gPGFF6OBjk5xrCquBewGLfRdDwcICdnfRPdtpwmijgrmoIjznjmHel3ZoO5DJKfhDpmC+79V8t4PCQjyc1Gw0qPc4MeMvDfKxWSU8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71MJRd9MrDNyOVv9CqCHpz++pe/kgTdIx955tAKWj9IB6ls9NjH2CA2qJdmz02RBYK94EC3UKFfwzyXyi4n+M1B36ytZWdE3v0+Vw8uRpeHesJ8VdWWHKjtMsyv9UA8znUQ9V5blp2C5yWCzQz5zVBtOyd0UTTgc9gEqacn12h8vR2Mb1RVOpxzDpRDRJgrJNOx+fA0KrnJSYFF27Oo3Ipl9HSaTV/4+6Le 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: List-Subscribe: List-Unsubscribe: From: Kairui Song Some useful comments were dropped in commit b56a2d8af914 ("mm: rid swapoff of quadratic complexity"), add them back. Signed-off-by: Kairui Song --- mm/swapfile.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 0008cd39af42..606d95b56304 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1881,6 +1881,17 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, folio = page_folio(page); } if (!folio) { + /* + * The entry could have been freed, and will not + * be reused since swapoff() already disabled + * allocation from here, or alloc_page() failed. + * + * We don't hold lock here, so the swap entry could be + * SWAP_MAP_BAD (when the cluster is discarding). + * Instead of fail out, We can just skip the swap + * entry because swapoff will wait for discarding + * finish anyway. + */ swp_count = READ_ONCE(si->swap_map[offset]); if (swp_count == 0 || swp_count == SWAP_MAP_BAD) continue;