From patchwork Tue Dec 8 02:50:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11957473 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 E4D69C4361B for ; Tue, 8 Dec 2020 02:50:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6D92823609 for ; Tue, 8 Dec 2020 02:50:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D92823609 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E3BAD8D000F; Mon, 7 Dec 2020 21:50:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC7418D0001; Mon, 7 Dec 2020 21:50:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6BE78D000F; Mon, 7 Dec 2020 21:50:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id AA64C8D0001 for ; Mon, 7 Dec 2020 21:50:29 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 75E11181AEF1D for ; Tue, 8 Dec 2020 02:50:29 +0000 (UTC) X-FDA: 77568586578.19.tank40_19130c7273e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 56D8B1AD1B9 for ; Tue, 8 Dec 2020 02:50:29 +0000 (UTC) X-HE-Tag: tank40_19130c7273e3 X-Filterd-Recvd-Size: 6404 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 02:50:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607395828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kzE0WQTA1Dwd5PkGUcDTN27r/6OT+CPdQW7/EJE5vos=; b=N26xIZ7M5QoeGUJtvFeHXCqZukJC+5EV8EqAUR6GCtlgplD760TQxHHCmFwLRA9f2+ZTYx g8Yy/DuF/krGotmREjWqcq+vdpxIscTGFR82VDaUph/f1t5R4/X7q01g6tGDvYWFGKBLpf nPkFGTo5mcB7CLXr5ff1LaWB6U9sWRo= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-85-_Jk2mow6NCSElRiLLQxq2g-1; Mon, 07 Dec 2020 21:50:26 -0500 X-MC-Unique: _Jk2mow6NCSElRiLLQxq2g-1 Received: by mail-qt1-f199.google.com with SMTP id o12so12846440qtw.14 for ; Mon, 07 Dec 2020 18:50:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kzE0WQTA1Dwd5PkGUcDTN27r/6OT+CPdQW7/EJE5vos=; b=JF6CE0FL8+j1WeOnv74X/DPNp21M7i20EGoRTx7Nttd8VJa/pdx5/pDLP2jqeN8V/H +M5nvQesUlVPJ/kFgZoTROue9gqKz5lyjzOU4sKwxvSUHfb/ycDkCB4JjWE37zEiwYwS Nce3rrCWVRtAsKTK1hMvPNyzCsTTi1jw5vWZNxKAwvu9c4Emtj4F50AIvkoTsBlW2BB9 6bmW7kzmzvD613/d5TTb8LqTKuMug5YbdNflm4hy7Tid3j8Ru7UAzhgvZK5UqNXL8Shn zIm0JDpIpvDDEdx2RpluA/sLJhB0CxqCMxCBolLnV3kEpzkR39PZ+jTLelLWaa9xJEud xyxQ== X-Gm-Message-State: AOAM530kb1zKNNwUa7nmJF61l2w5/IBYFgVnZAMgP/YQp1nX/oxtwpG4 HiF76VcfOUeYonoj6xvgy5D+YSC/bKOhCfTlMH4TwhfrkLiqtiIrM4HOeM2sDd6XnhCgC6varTo K11PzGwGQmjI= X-Received: by 2002:a05:620a:a9a:: with SMTP id v26mr27449734qkg.56.1607395826012; Mon, 07 Dec 2020 18:50:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/BqcivJZFIop18PT06X3Iy/glDGRBOA2o1sTDQkDzVRUfyfyhCPefW8cuvWaFM1lo8SkbhA== X-Received: by 2002:a05:620a:a9a:: with SMTP id v26mr27449718qkg.56.1607395825822; Mon, 07 Dec 2020 18:50:25 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id a28sm2632766qtm.80.2020.12.07.18.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 18:50:25 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrea Arcangeli , peterx@redhat.com, "Kirill A . Shutemov" , Andrew Morton Subject: [PATCH 1/3] mm: Drop first_index/last_index in zap_details Date: Mon, 7 Dec 2020 21:50:20 -0500 Message-Id: <20201208025022.8234-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201208025022.8234-1-peterx@redhat.com> References: <20201208025022.8234-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: The first_index/last_index parameters in zap_details are actually only used in unmap_mapping_range_tree(). At the meantime, this function is only called by unmap_mapping_pages() once. Instead of passing these two variables through the whole stack of page zapping code, remove them from zap_details and let them simply be parameters of unmap_mapping_range_tree(), which is inlined. Signed-off-by: Peter Xu --- include/linux/mm.h | 2 -- mm/memory.c | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 16b799a0522c..5d977e484095 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1625,8 +1625,6 @@ extern void user_shm_unlock(size_t, struct user_struct *); */ struct zap_details { struct address_space *check_mapping; /* Check page->mapping if set */ - pgoff_t first_index; /* Lowest page->index to unmap */ - pgoff_t last_index; /* Highest page->index to unmap */ }; struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index eeae590e526a..70d57c39380d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3136,20 +3136,20 @@ static void unmap_mapping_range_vma(struct vm_area_struct *vma, } static inline void unmap_mapping_range_tree(struct rb_root_cached *root, + pgoff_t first_index, + pgoff_t last_index, struct zap_details *details) { struct vm_area_struct *vma; pgoff_t vba, vea, zba, zea; - vma_interval_tree_foreach(vma, root, - details->first_index, details->last_index) { - + vma_interval_tree_foreach(vma, root, first_index, last_index) { vba = vma->vm_pgoff; vea = vba + vma_pages(vma) - 1; - zba = details->first_index; + zba = first_index; if (zba < vba) zba = vba; - zea = details->last_index; + zea = last_index; if (zea > vea) zea = vea; @@ -3175,17 +3175,17 @@ static inline void unmap_mapping_range_tree(struct rb_root_cached *root, void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, pgoff_t nr, bool even_cows) { + pgoff_t first_index = start, last_index = start + nr - 1; struct zap_details details = { }; details.check_mapping = even_cows ? NULL : mapping; - details.first_index = start; - details.last_index = start + nr - 1; - if (details.last_index < details.first_index) - details.last_index = ULONG_MAX; + if (last_index < first_index) + last_index = ULONG_MAX; i_mmap_lock_write(mapping); if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root))) - unmap_mapping_range_tree(&mapping->i_mmap, &details); + unmap_mapping_range_tree(&mapping->i_mmap, first_index, + last_index, &details); i_mmap_unlock_write(mapping); } From patchwork Tue Dec 8 02:50:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11957477 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 D5C96C4361B for ; Tue, 8 Dec 2020 02:50:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6B06923609 for ; Tue, 8 Dec 2020 02:50:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B06923609 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 49F8D8D0011; Mon, 7 Dec 2020 21:50:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42DF98D0001; Mon, 7 Dec 2020 21:50:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 148898D0011; Mon, 7 Dec 2020 21:50:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id E13CE8D0001 for ; Mon, 7 Dec 2020 21:50:32 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B26FA180AD815 for ; Tue, 8 Dec 2020 02:50:32 +0000 (UTC) X-FDA: 77568586704.28.skirt01_38042e2273e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 96DB16D67 for ; Tue, 8 Dec 2020 02:50:32 +0000 (UTC) X-HE-Tag: skirt01_38042e2273e3 X-Filterd-Recvd-Size: 8176 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 02:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607395831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1zmhnvZUSAT9HT8Rbhab0qM8yDo/F72PDPxbzWHzkX0=; b=jEBagklYtExtHUPqzuXM9zJWY0qYjmZN+5NEG0O0TZYNn3IJdOU3t+65I3k2KVbjNeZmjE tlVkTzGkv7IeI6zF8QGpO4CGoCZ6OqftvITjjQLGRmvHB+RksYTw5tQdcQHH2qYMdUWLHL 8kwwBhI23GFETtjRcqpXW0tKk1adwsg= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-id9CjWljOfeR-CJgADRQQg-1; Mon, 07 Dec 2020 21:50:28 -0500 X-MC-Unique: id9CjWljOfeR-CJgADRQQg-1 Received: by mail-qk1-f200.google.com with SMTP id b11so14250645qkk.10 for ; Mon, 07 Dec 2020 18:50:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1zmhnvZUSAT9HT8Rbhab0qM8yDo/F72PDPxbzWHzkX0=; b=PGVOxmMRVkChPYyOcizUl+4fbIF6IxLlkADXWITSXGek1StMO3yvvTzCIz6L66pEow qXuZQdoHVDM2Q9SANUhtI3hLtB1pBPdNYKHI2K+lLqWmyQUZfYboBGarjlCvta47fbc4 Jz0CyVNV1Dk1/8BRFy5quLe7Z0vI7huhbcG1dnMb/s1Mm6IEkIBV6YcNQMxSDMB1DIbh njWsOPLHfAENqjUmQC3msTK2z9GZEkmP32suXSO/9lf/XZWXhzcjsO2fcgdrqW+Frn6P PygwxJbUV84V3qHF9nQUb7KkvwZSQPDBhYziGDv7bMGBkmXQPCKw649ZookhNfP9Tgb7 cqXw== X-Gm-Message-State: AOAM532rjzUqN9e+IKzXTAVoi5nGPEIPWyOsNCdd4zWO4buI/lMmb/3l AsG5Ghxu8W7WoJ0bhS8cfKRJpZxeE/DJBU4b00VylfxGx3rqWe9iWQ0LbmIcNyp11wx9DxK1hXp SgrXdcMHX7Co= X-Received: by 2002:ac8:6b86:: with SMTP id z6mr27358539qts.26.1607395827599; Mon, 07 Dec 2020 18:50:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzY8pmpVE01uuFXf+fUJmcxo7NWgrHtZoBueRunXhjVH/tM0j0V2OQkmMM/a50rNIjWgvvmmg== X-Received: by 2002:ac8:6b86:: with SMTP id z6mr27358528qts.26.1607395827344; Mon, 07 Dec 2020 18:50:27 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id a28sm2632766qtm.80.2020.12.07.18.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 18:50:26 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrea Arcangeli , peterx@redhat.com, "Kirill A . Shutemov" , Andrew Morton Subject: [PATCH 2/3] mm: Introduce zap_details.zap_flags Date: Mon, 7 Dec 2020 21:50:21 -0500 Message-Id: <20201208025022.8234-3-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201208025022.8234-1-peterx@redhat.com> References: <20201208025022.8234-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: Instead of trying to introduce one variable for every new zap_details fields, let's introduce a flag so that it can start to encode true/false informations. Let's start to use this flag first to clean up the only check_mapping variable. Firstly, the name "check_mapping" implies this is a "boolean", but actually it stores the mapping inside, just in a way that it won't be set if we don't want to check the mapping. To make things clearer, introduce the 1st zap flag ZAP_FLAG_CHECK_MAPPING, so that we only check against the mapping if this bit set. At the same time, we can rename check_mapping into zap_mapping and set it always. Since at it, introduce another helper zap_check_mapping_skip() and use it in zap_pte_range() properly. Some old comments have been removed in zap_pte_range() because they're duplicated, and since now we're with ZAP_FLAG_CHECK_MAPPING flag, it'll be very easy to grep this information by simply grepping the flag. It'll also make life easier when we want to e.g. pass in zap_flags into the callers like unmap_mapping_pages() (instead of adding new booleans besides the even_cows parameter). Signed-off-by: Peter Xu --- include/linux/mm.h | 19 ++++++++++++++++++- mm/memory.c | 31 ++++++++----------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5d977e484095..7ed4352ec84f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1620,13 +1620,30 @@ static inline bool can_do_mlock(void) { return false; } extern int user_shm_lock(size_t, struct user_struct *); extern void user_shm_unlock(size_t, struct user_struct *); +/* Whether to check page->mapping when zapping */ +#define ZAP_FLAG_CHECK_MAPPING BIT(0) + /* * Parameter block passed down to zap_pte_range in exceptional cases. */ struct zap_details { - struct address_space *check_mapping; /* Check page->mapping if set */ + struct address_space *zap_mapping; /* Check page->mapping if set */ + unsigned long zap_flags; /* Special flags for zapping */ }; +/* Return true if skip zapping this page, false otherwise */ +static inline bool +zap_check_mapping_skip(struct zap_details *details, struct page *page) +{ + if (!details || !page) + return false; + + if (!(details->zap_flags & ZAP_FLAG_CHECK_MAPPING)) + return false; + + return details->zap_mapping != page_rmapping(page); +} + struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, pte_t pte); struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index 70d57c39380d..20a8ba05c334 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1220,16 +1220,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, struct page *page; page = vm_normal_page(vma, addr, ptent); - if (unlikely(details) && page) { - /* - * unmap_shared_mapping_pages() wants to - * invalidate cache without truncating: - * unmap shared but keep private pages. - */ - if (details->check_mapping && - details->check_mapping != page_rmapping(page)) - continue; - } + if (unlikely(zap_check_mapping_skip(details, page))) + continue; ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); tlb_remove_tlb_entry(tlb, pte, addr); @@ -1261,17 +1253,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (is_device_private_entry(entry)) { struct page *page = device_private_entry_to_page(entry); - if (unlikely(details && details->check_mapping)) { - /* - * unmap_shared_mapping_pages() wants to - * invalidate cache without truncating: - * unmap shared but keep private pages. - */ - if (details->check_mapping != - page_rmapping(page)) - continue; - } - + if (unlikely(zap_check_mapping_skip(details, page))) + continue; pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); rss[mm_counter(page)]--; page_remove_rmap(page, false); @@ -3176,9 +3159,11 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, pgoff_t nr, bool even_cows) { pgoff_t first_index = start, last_index = start + nr - 1; - struct zap_details details = { }; + struct zap_details details = { .zap_mapping = mapping }; + + if (!even_cows) + details.zap_flags |= ZAP_FLAG_CHECK_MAPPING; - details.check_mapping = even_cows ? NULL : mapping; if (last_index < first_index) last_index = ULONG_MAX; From patchwork Tue Dec 8 02:50:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11957475 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 3CAF4C433FE for ; Tue, 8 Dec 2020 02:50:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC9E923976 for ; Tue, 8 Dec 2020 02:50:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC9E923976 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 627F58D0010; Mon, 7 Dec 2020 21:50:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AFDD8D0001; Mon, 7 Dec 2020 21:50:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47AF58D0010; Mon, 7 Dec 2020 21:50:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 2C6BB8D0001 for ; Mon, 7 Dec 2020 21:50:32 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E76471EE6 for ; Tue, 8 Dec 2020 02:50:31 +0000 (UTC) X-FDA: 77568586662.20.berry51_0502511273e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id C2E2A180C0609 for ; Tue, 8 Dec 2020 02:50:31 +0000 (UTC) X-HE-Tag: berry51_0502511273e3 X-Filterd-Recvd-Size: 6532 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 02:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607395830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y3Z2K8nRRfGkaf6Txv+p5jeGljoBTJFR0t93dd3Zx9U=; b=OravxRtp7sJzKPslssZdgNiRssCvpkub//k0LRYGTozhFXM7QAC8PJiwo6nGpZ73DzrAMW A/AnaT5VgCWIe3YWpqXUZ9viacfuyII3AMueGs6CK/RrAQkadjPd1odeEDfFqTS8kY7tgw I63hyyDHDTygUXCm+st7K0l/XmlQiNE= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-268-2fPEp6UEN0O54d6c1rjmEQ-1; Mon, 07 Dec 2020 21:50:29 -0500 X-MC-Unique: 2fPEp6UEN0O54d6c1rjmEQ-1 Received: by mail-qk1-f197.google.com with SMTP id q206so14246874qka.14 for ; Mon, 07 Dec 2020 18:50:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y3Z2K8nRRfGkaf6Txv+p5jeGljoBTJFR0t93dd3Zx9U=; b=iohFhze2/pm8nQIjcIa8c+J4zwrAkmsDQigPcejBBk0BWskgIMSU9bRR4xCsNQ4LdJ J+4ugyuPCCs1Mn/We90EmwH3emM745hn8khCTQzKJ4rELJ4f9ii9MB3xHAfCnoRjWFCR 7QE0p5lpboZVKqwZuJpOvNkjq+2lLWSAeH2DTqfk1dEQlpE1wfo6drI7+GKmLYsS+Ce4 6ujST/AQLT3egNZlxqxEZm5NEUcRLa/EsuzZfiFGyraVJgAW54sSkMVQemHbhK9yDFIl BQ+PWxGHLqKp5uIlZOozCmv2RFlShN2s8YFpDdzid08EqA2XGd7KYG4/1ySjV6lRUn82 Qrzw== X-Gm-Message-State: AOAM532+/76n54QmwQTAc8eat7WDoQvdPBvDKhypBZDxBQ0Vq/wCu+vB BaNpR6O2yRs/cN9d7NPfrsOW1AtSB28v2CWDKskNIFJNF079Zu4gvAbvtMnzMlzPuGpSASwsT5g n2s73QqU+LPI= X-Received: by 2002:a0c:c405:: with SMTP id r5mr16720984qvi.4.1607395828946; Mon, 07 Dec 2020 18:50:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHzUEslTZ1FZEWzJNu0W0qlP5gzOXXVxFImV3fi6ypeqsM2vcqg63+0O0dcsbZ71OFP2qwyQ== X-Received: by 2002:a0c:c405:: with SMTP id r5mr16720969qvi.4.1607395828714; Mon, 07 Dec 2020 18:50:28 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id a28sm2632766qtm.80.2020.12.07.18.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 18:50:28 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrea Arcangeli , peterx@redhat.com, "Kirill A . Shutemov" , Andrew Morton Subject: [PATCH 3/3] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Mon, 7 Dec 2020 21:50:22 -0500 Message-Id: <20201208025022.8234-4-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201208025022.8234-1-peterx@redhat.com> References: <20201208025022.8234-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: Firstly, the comment in zap_pte_range() is misleading because it checks against details rather than check_mappings, so it's against what the code did. Meanwhile, it's confusing too on not explaining why passing in the details pointer would mean to skip all swap entries. New user of zap_details could very possibly miss this fact if they don't read deep until zap_pte_range() because there's no comment at zap_details talking about it at all, so swap entries could be errornously skipped without being noticed. This partly reverts 3e8715fdc03e ("mm: drop zap_details::check_swap_entries"), but introduce ZAP_FLAG_SKIP_SWAP flag, which means the opposite of previous "details" parameter: the caller should explicitly set this to skip swap entries, otherwise swap entries will always be considered (which is still the major case here). Cc: Kirill A. Shutemov Signed-off-by: Peter Xu --- include/linux/mm.h | 12 ++++++++++++ mm/memory.c | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 7ed4352ec84f..16631ee5eb9d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1622,6 +1622,8 @@ extern void user_shm_unlock(size_t, struct user_struct *); /* Whether to check page->mapping when zapping */ #define ZAP_FLAG_CHECK_MAPPING BIT(0) +/* Whether to skip zapping swap entries */ +#define ZAP_FLAG_SKIP_SWAP BIT(1) /* * Parameter block passed down to zap_pte_range in exceptional cases. @@ -1644,6 +1646,16 @@ zap_check_mapping_skip(struct zap_details *details, struct page *page) return details->zap_mapping != page_rmapping(page); } +/* Return true if skip swap entries, false otherwise */ +static inline bool +zap_skip_swap(struct zap_details *details) +{ + if (!details) + return false; + + return details->zap_flags & ZAP_FLAG_SKIP_SWAP; +} + struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, pte_t pte); struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index 20a8ba05c334..c9945f3c374d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1262,8 +1262,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, continue; } - /* If details->check_mapping, we leave swap entries. */ - if (unlikely(details)) + if (unlikely(zap_skip_swap(details))) continue; if (!non_swap_entry(entry)) @@ -3159,7 +3158,10 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, pgoff_t nr, bool even_cows) { pgoff_t first_index = start, last_index = start + nr - 1; - struct zap_details details = { .zap_mapping = mapping }; + struct zap_details details = { + .zap_mapping = mapping, + .zap_flags = ZAP_FLAG_SKIP_SWAP, + }; if (!even_cows) details.zap_flags |= ZAP_FLAG_CHECK_MAPPING;