Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1222060rwb; Tue, 27 Sep 2022 09:58:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5MgQIp445WxQofDQW7aVESBd+zfhC8qV2Ls+eEdjGb1qhubXoS+Y4140J76UcZWv4FB53M X-Received: by 2002:a17:90b:3b47:b0:202:a81f:4059 with SMTP id ot7-20020a17090b3b4700b00202a81f4059mr5713814pjb.150.1664297914672; Tue, 27 Sep 2022 09:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664297914; cv=none; d=google.com; s=arc-20160816; b=Xn370YYVgQ5OSX+AT2VR4L/l4JxQDjNjHYVJ95lD4cazPRn9JPXwVLBXPhsUtL2ut0 PRYfQU6U825CVxxEeGtT8o6ywri+TCdlxvMwHGITbD3VB/P7Sncty4gi6yVnyXV1XaEK /4ejpyUt51+CinX81Mb9RdyaxdO4xmkL4R647bZqK/eMunfsYf40OXzDxfJZ5iV8AHwB ilxXrwLRQCP0MxbN99nyO3/bpYpJ6tVWTDR+oyEGOz4DUGadIKzXXP8tBPIm/bGFrggO kGB625kaz1tdpiP5hsSsRjcZch4qdUgMinLj02PmBgb/T7mRtolPXUiHfvIipGXAzsxW imCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AsJY41XMXFwgdgJedGBIEW9iEXdmuZaxFchvtZgLRts=; b=C9V+hLC5b7Bc72/1iWtSWLo4fcSchFexcxK+9cLJ216HzBJb4a1lYrfvSCJMQPYH3C STZbiVntJw1HLxFxPaeF5qDb3PL4mLX7d68X2D+pF6ViUe1+T+LAsN2AeprzLMYxi6GF kdinY/S+pTLpvNtn8AJ41uWzErTem7+xXKJHRT7iwBUt4q1aeU8vWC1tjE8zE+/61T5Q TlpudbifzVDLubUnsHVWxguikS4IYEpduA303HBRLe2IjfmoCx+6DvZI2O4JmqmAqpbV xsDGaDJwkG9gBHK+BDicgqEilNXYG7nbeoJ5+i+etEtb96sMe+6BbhdUKNdWiJK65c/y amfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=m6GcP6wW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l192-20020a633ec9000000b00438e839828bsi2585891pga.72.2022.09.27.09.58.21; Tue, 27 Sep 2022 09:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=m6GcP6wW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231851AbiI0Q3D (ORCPT + 99 others); Tue, 27 Sep 2022 12:29:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233066AbiI0Q2d (ORCPT ); Tue, 27 Sep 2022 12:28:33 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344E51D73C0 for ; Tue, 27 Sep 2022 09:28:21 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d24so9564060pls.4 for ; Tue, 27 Sep 2022 09:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=AsJY41XMXFwgdgJedGBIEW9iEXdmuZaxFchvtZgLRts=; b=m6GcP6wWedee5WJZJaWbkT5RTdd55uan6Np016DjpR8muG6vIptBwf3QzE4ERNpttX affNl+gUFcSzOYXosWJ/VRNjxYXy6FJfUHO5liFb7f0D5IstX1F597GLJSGrDA7jLhUD agxRfB3pWC7X6zWYvj7pwv0ePgUXr9cf1klPUuTHnNmaQhlQA0/PzaK0mKwVXiZUPXMj OZSsmozTQGpDPKL7eaUGXjsln2FL4L4E1wk/WU0AWbsxNpjOvcdECApM3/JSfUfxUR1B /ivlVLd+zH8EmphX+KW4fYQo4eRP8Tu2zNIh1l1qyg+uW8hsnnAiVXXZYMF2KwGSTiBq rHnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=AsJY41XMXFwgdgJedGBIEW9iEXdmuZaxFchvtZgLRts=; b=vrgCuG15IJzeQU7BBhj6kXrdX1+LCQcXlvunXrVX2V0uARqoKj+eDVbwrrpHIvnhnS DF0I+vFXgK0hV09vcI8/qCD4FQFOufYOqwZX122qx/jRTf6nVyMwmLR1S+LGYIAvS4Pp 2xmraXaKgmX2W7XZGEuM1/QxShK2a6dF0YguBpvci7FAw8U9b/MBNyKEQCnlVf4f2fCk SHL2XZ9Zy3ykTZDmBsvLZRq8iiHX1y0mAK8r8z4RUpftK24rk1wAJRKgGjAGLvWFarRt mobLqTikZyvQoufwOWYdjWO7G06quAoUw4u20ZliIXsBU3QFCSwIFzsceEOm3psGdwa5 nNzg== X-Gm-Message-State: ACrzQf1a1ySS3GtGOZnPW9pRKGGfcrvXC5vt/1lLdVcyru0i8lFgEm8G no05zvyfE7DrrKlRt/jvmg8= X-Received: by 2002:a17:90b:3e86:b0:205:d88c:616d with SMTP id rj6-20020a17090b3e8600b00205d88c616dmr4387498pjb.78.1664296100553; Tue, 27 Sep 2022 09:28:20 -0700 (PDT) Received: from archlinux.localdomain ([140.121.198.213]) by smtp.googlemail.com with ESMTPSA id 9-20020a17090a0f0900b001f333fab3d6sm8602360pjy.18.2022.09.27.09.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 09:28:19 -0700 (PDT) From: Chih-En Lin To: Andrew Morton , Qi Zheng , David Hildenbrand , Matthew Wilcox , Christophe Leroy Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Luis Chamberlain , Kees Cook , Iurii Zaikin , Vlastimil Babka , William Kucharski , "Kirill A . Shutemov" , Peter Xu , Suren Baghdasaryan , Arnd Bergmann , Tong Tiangen , Pasha Tatashin , Li kunyu , Nadav Amit , Anshuman Khandual , Minchan Kim , Yang Shi , Song Liu , Miaohe Lin , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , Fenghua Yu , Dinglan Peng , Pedro Fonseca , Jim Huang , Huichun Feng , Chih-En Lin Subject: [RFC PATCH v2 8/9] mm: Handle COW PTE with reclaim algorithm Date: Wed, 28 Sep 2022 00:29:56 +0800 Message-Id: <20220927162957.270460-9-shiyn.lin@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220927162957.270460-1-shiyn.lin@gmail.com> References: <20220927162957.270460-1-shiyn.lin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To avoid the PFRA reclaiming the page resided in the COWed PTE table, break COW when it using rmap to unmap all the processes. Signed-off-by: Chih-En Lin --- include/linux/rmap.h | 2 ++ mm/page_vma_mapped.c | 5 +++++ mm/rmap.c | 2 +- mm/swapfile.c | 1 + mm/vmscan.c | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index b89b4b86951f8..5c7e3bedc068b 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -312,6 +312,8 @@ int make_device_exclusive_range(struct mm_struct *mm, unsigned long start, #define PVMW_SYNC (1 << 0) /* Look for migration entries rather than present PTEs */ #define PVMW_MIGRATION (1 << 1) +/* Break COW PTE during the walking */ +#define PVMW_COW_PTE (1 << 2) struct page_vma_mapped_walk { unsigned long pfn; diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index 8e9e574d535aa..5008957bbe4a7 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -251,6 +251,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) step_forward(pvmw, PMD_SIZE); continue; } + + /* TODO: Does breaking COW PTE here is correct? */ + if (pvmw->flags & PVMW_COW_PTE) + handle_cow_pte(vma, pvmw->pmd, pvmw->address, false); + if (!map_pte(pvmw)) goto next_pte; this_pte: diff --git a/mm/rmap.c b/mm/rmap.c index 93d5a6f793d20..8f737cb44e48a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1477,7 +1477,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, unsigned long address, void *arg) { struct mm_struct *mm = vma->vm_mm; - DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0); + DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, PVMW_COW_PTE); pte_t pteval; struct page *subpage; bool anon_exclusive, ret = true; diff --git a/mm/swapfile.c b/mm/swapfile.c index 1fdccd2f1422e..ef4d3d81a824b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1916,6 +1916,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, do { cond_resched(); next = pmd_addr_end(addr, end); + handle_cow_pte(vma, pmd, addr, false); if (pmd_none_or_trans_huge_or_clear_bad(pmd)) continue; ret = unuse_pte_range(vma, pmd, addr, next, type); diff --git a/mm/vmscan.c b/mm/vmscan.c index b2b1431352dcd..030fad3d310d9 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1822,6 +1822,7 @@ static unsigned int shrink_page_list(struct list_head *page_list, /* * The folio is mapped into the page tables of one or more * processes. Try to unmap it here. + * It will write to the page tables, break COW PTE here. */ if (folio_mapped(folio)) { enum ttu_flags flags = TTU_BATCH_FLUSH; -- 2.37.3