From patchwork Thu Jan 18 11:10:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13522711 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 56BF6C4707B for ; Thu, 18 Jan 2024 11:11:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9BB56B0087; Thu, 18 Jan 2024 06:11:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4C846B0088; Thu, 18 Jan 2024 06:11:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D141F6B0089; Thu, 18 Jan 2024 06:11:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C05096B0087 for ; Thu, 18 Jan 2024 06:11:50 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8FDD3802D6 for ; Thu, 18 Jan 2024 11:11:50 +0000 (UTC) X-FDA: 81692166780.24.B594C39 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf30.hostedemail.com (Postfix) with ESMTP id BD60080017 for ; Thu, 18 Jan 2024 11:11:48 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=S9ekOocR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705576308; a=rsa-sha256; cv=none; b=Z1GIvtDVf1x4PtegKsFV6f1dwto7Pzj+SXco2J406DKFVcNa/dT4Fa2DYa6n6MR8/S30SG PvJ1R/xXJLRy8AzOjMP9c5udGL1Vl6sEavNm+L+Bn8gXqSL1aFp998gFbkm/1WUD62Kr5d YkaBVW0Gx1+w1pSn0z6413WLfh49kn4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=S9ekOocR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705576308; h=from:from:sender: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=xZZoI8vzJz6uaOc3IP6SaeIVpVjWcCgJVsn6AMZhjDQ=; b=eWVgWIgtEQUwyfJqR9klOGIJjjr9sPIONHsQN49O0WFUhfzqsQqygCd71BOYjmUY1ry+Ca bzymvIwZ2gXb6fGZOFhGQ/MiUIroUxloX9OJrmd1PQ4eB+sZzrREXqRUVoBVMWMQSqIoHx qAdL5O37aGAw2XN7qQbYzd5MQi9WIVk= Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5cdfed46372so9888441a12.3 for ; Thu, 18 Jan 2024 03:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705576307; x=1706181107; darn=kvack.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=xZZoI8vzJz6uaOc3IP6SaeIVpVjWcCgJVsn6AMZhjDQ=; b=S9ekOocRt9jTQPDIfgX+CjvcvyrHVMotoL4eCeni5YI11tRHdrfr4cr6PyRccVnkWW sdEoZFUfR0UKozyk57ZGJ+TC2ZG4v7zBh/Zo1DTPLtZm6Y5EcZdPUstnI9g4z8i4X1Kt xN9+VkAqdL2zUZeRbHd0X6P13xGpCwtZUdR1Rvg0L6KtgU8I7x5ghdFSdra/VHlYt70O uGhWlknZarKcCxNsnjeME65TGNpgrJJlEciOn4WSeT186ZJZn22gPBjsYJSS+fS7PxZ+ Du6xcQeL32CuCtMY3tGCFbgmW/wY43n7tK1JYfmxkRi6azO2wXWDSXJP6K8dbvn8mAKG ZMog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705576307; x=1706181107; 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=xZZoI8vzJz6uaOc3IP6SaeIVpVjWcCgJVsn6AMZhjDQ=; b=pFwDohG32cud4Rl6aLmKqiyDqkuF/sRMklctRqp/KWcYHt/lTpPy1pNccg+UunFCSF uGbeUbC+HihS9sanMIVU0yV8BnOL53PV801v/LESN/47nyYsLxayERLJrbClvzhNLIjb SRsMQIP7lK6HciM3DuoM63lHqMTXuFLp6Ke6BhtMmHCRh3xr0cxG37D9gQIw9c6ERX7C J5jxW+XrGlCaj5cRdCCoIUO7a3v6vUSfcTJWIaXZ4EpUIFF7jvLaGFZkMGu08jTdPw20 K8SmoFDXo4h9GOMIBfDmHuGzzmA4xac6osHC29rzIIkRE3wLH03Vj7YQrqe3XXXN+nQb 7nrw== X-Gm-Message-State: AOJu0YxxaqIo763xHb9BdV2dER7IuKqy3+ZkzNs9PH48nggK838DZRGp pVTPeVP59cYM9iHkyTmq+m3XQdu+wpk22letpadXWucQgBvaAftm X-Google-Smtp-Source: AGHT+IGrNGM+/9wCFNZHoUn+TpVS1dFfrjzlPUiB7OyAY2gO2fREpkC0FCj3Devi0x2OTNRIh4y8Ug== X-Received: by 2002:a05:6a20:9f9b:b0:199:e4ab:691c with SMTP id mm27-20020a056a209f9b00b00199e4ab691cmr731200pzb.8.1705576307486; Thu, 18 Jan 2024 03:11:47 -0800 (PST) Received: from barry-desktop.. (143.122.224.49.dyn.cust.vf.net.nz. [49.224.122.143]) by smtp.gmail.com with ESMTPSA id t19-20020a056a0021d300b006d9be753ac7sm3039107pfj.108.2024.01.18.03.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 03:11:47 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: ryan.roberts@arm.com, akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, mhocko@suse.com, shy828301@gmail.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com, surenb@google.com, steven.price@arm.com, Chuanhua Han , Barry Song Subject: [PATCH RFC 3/6] mm: swap: make should_try_to_free_swap() support large-folio Date: Fri, 19 Jan 2024 00:10:33 +1300 Message-Id: <20240118111036.72641-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240118111036.72641-1-21cnbao@gmail.com> References: <20231025144546.577640-1-ryan.roberts@arm.com> <20240118111036.72641-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BD60080017 X-Stat-Signature: 75u36uh7wgo7mujh5rcw9o5nijt7zstp X-HE-Tag: 1705576308-978682 X-HE-Meta: U2FsdGVkX1/m5VJcRNGpGfeDObBeWKUti7l6JPSNamc685fRL1sJF9frUy/Vs+CgypCjCbhJ5kkxV4uxTCB+s+8+sDDX2mKb83R11Y2WurSQlARKemJHoDcKYXTpo1qfA9hvK7ULM6aC/CbDmOG7VdP/4xx681ymy6wLUl83+l6NKH7h+vtx8pVB2oijyv/8bzJFXEfYMXgETbqlPKf10MueGAzET2MNIqelUxO8hPsBf+M+62fT2fMXCW57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0aaLiDxLuXCGgpTkO8HqRhxFgPT5Q7aJwQigy5l5xLWeJAWC56k6fku2yvGv3H6bKGkKDWJtjEEdu4mJHYxnHWfwaYLC8voYnE0reLHbR7uguyCNXAhhQAZxNxW015/oZxQSFKn72R/Zp5g4fk9iPbMNGbuv2W2wb3+Xq0h9lQqMwPVGSbFm6hgboKoGjOkPHm4+mnoY+OaY92aRTqvkvpRBmfrEDAKX+Z6AM3vu8sw== 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: Chuanhua Han should_try_to_free_swap() works with an assumption that swap-in is always done at normal page granularity, aka, folio_nr_pages = 1. To support large folio swap-in, this patch removes the assumption. Signed-off-by: Chuanhua Han Co-developed-by: Barry Song Signed-off-by: Barry Song Acked-by: Chris Li --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 7e1f4849463a..f61a48929ba7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3714,7 +3714,7 @@ static inline bool should_try_to_free_swap(struct folio *folio, * reference only in case it's likely that we'll be the exlusive user. */ return (fault_flags & FAULT_FLAG_WRITE) && !folio_test_ksm(folio) && - folio_ref_count(folio) == 2; + folio_ref_count(folio) == (1 + folio_nr_pages(folio)); } static vm_fault_t pte_marker_clear(struct vm_fault *vmf)