From mboxrd@z Thu Jan 1 00:00:00 1970 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 08245C433EF for ; Thu, 16 Dec 2021 18:56:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90CD26B0073; Thu, 16 Dec 2021 13:56:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BCD86B0074; Thu, 16 Dec 2021 13:56:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7837C6B0075; Thu, 16 Dec 2021 13:56:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 6A8736B0073 for ; Thu, 16 Dec 2021 13:56:45 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 28C94181AC9CC for ; Thu, 16 Dec 2021 18:56:35 +0000 (UTC) X-FDA: 78924563550.17.7E1208B Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by imf16.hostedemail.com (Postfix) with ESMTP id 88DBE18000F for ; Thu, 16 Dec 2021 18:56:33 +0000 (UTC) Received: by mail-lj1-f171.google.com with SMTP id b19so38143781ljr.12 for ; Thu, 16 Dec 2021 10:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=T72iEa6/PMxTzObrMeh+2//gQVFDpj/shBMd3gmg1uw=; b=NvCYSUxSU3U8BWuPW2q5BBzijI3Y0jqT0/A+Gh2JSKzJJFzh7A41O9UmM/3mEMqv/8 F61Bf6/WqeWTT0qioeYsKOLLvCndoZN+fdAgxc9J/xwf/21uVX+KIyMBimugITEs6o7m YCOeqUqYn8X7oIUVVjVlMm30YIzQtjedX/BjPG/RKB3E9PQCmIrZWokmIQj+SXiqgrwO 29+7McgoZXAtqYrvN13SgNvm8RzB6buIgA1yyHOfik6VnOTCSDxAnUhKKa/kn4OU933c 87VGZUr441LFg27LHsMJiCGbpGkk2HwY2zpNTMPFhwbQI5lxhy4q6NbgHurG/HgH7K9G xGZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=T72iEa6/PMxTzObrMeh+2//gQVFDpj/shBMd3gmg1uw=; b=p+6bQooDetGJqa6je+eFLEPP+uFdemjTkLVPDkuFXl1ezkYEsEEMQ7Nfv/8dlgnLHe sixT4cqtgiqOKhWkRZmCye7DQwoygYdRBJIzQ4Bud62LXnsXJ6WkJ+w4q2GtL9c9UA/L cpzMFNSBqsh4p6I3/Aor5CWPKq8hyJn25VS546GPg/6SW3sbNEe4GRqIAjB68ndS74qi ULBGJk2dfS4V+yx/BD3gNVTZuRaA8K/HWWjsHXtCvkU6AGQ7Z9KMWSPcf6EIeNY1PAOV Oxqkns2sHHM1kg6SJ3IL9ZV7BY/uSVUlE0VHKeqwcjfJOeqAo5Vud5oQhahEFSE/J19A JF8Q== X-Gm-Message-State: AOAM532jH3fxB32ef4UnzV4qRrpMMvKsPPWiZcWxYwzuswKe6jB1soF6 sDnfvTRD29/VvtVD6MrF5altUA== X-Google-Smtp-Source: ABdhPJxTlp9DUtefWyc02VwjBwbHOInDfJ3Kk0FEDstvjQRhQutLkJyxv1Pns6Y5VCmNQxocGJnjLg== X-Received: by 2002:a2e:9e59:: with SMTP id g25mr16411423ljk.464.1639680991697; Thu, 16 Dec 2021 10:56:31 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id o15sm998253lfk.175.2021.12.16.10.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 10:56:31 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 6FD5E103C3C; Thu, 16 Dec 2021 21:56:36 +0300 (+03) Date: Thu, 16 Dec 2021 21:56:36 +0300 From: "Kirill A. Shutemov" To: Matthew Wilcox Cc: linux-mm@kvack.org, Hugh Dickins , David Hildenbrand , Mike Kravetz Subject: Re: folio mapcount Message-ID: <20211216185636.oqymb5zzb7p6btbn@box.shutemov.name> References: <20211216093737.7w2fv7p7j2rrx5r6@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=shutemov-name.20210112.gappssmtp.com header.s=20210112 header.b=NvCYSUxS; spf=none (imf16.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.208.171) smtp.mailfrom=kirill@shutemov.name; dmarc=none X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 88DBE18000F X-Stat-Signature: 4xetdg4zaq91j5eqqbbqcnrowxxzjbkb X-HE-Tag: 1639680993-614067 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: On Thu, Dec 16, 2021 at 01:56:57PM +0000, Matthew Wilcox wrote: > > Okay, so you will have mapcount == 2 or 3 for mprotect case above, not > > 512. But it doesn't help with answering question if the page can be > > re-used. You would need to do rmap walk to get the answer. > > > > Note also that VMA lifecycle is different from page lifecycle: > > MADV_DONTNEED removes mapping, but leaves VMA intact. Who would decrement > > mapcount here? > > I think page_remove_rmap() does when called from zap_huge_pmd(). > The tricky part is handling partial DONTNEED calls. eg we could have > a 2MB page (if we're talking about shmem, it could even be mapped > askew), MADV_DONTNEED the first 512KB, then MADV_DONTNEED the last > 512KB, then finally MADV_DONTNEED the middle 1MB and only at the third > call should the mapcount be decremented. > > So a zap call has to check all the PTE/PMD entries in the range of the > (folio intersect vma) to be sure that there are no more references to > a part of this folio. It might not be terribly fast, but it probably > won't be noticable compared to all the other costs of doing a munmap(). It's not only the area around unmapped. The rest of the page can be anywhere in the address space, thanks to mremap(2). I think it would require full rmap, but I'm not sure. Or some very special tricks on mremap() or vma split. Looks like suffling complexity around, not reducing it. -- Kirill A. Shutemov