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 38159C05027 for ; Thu, 26 Jan 2023 09:11:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E9468E0001; Thu, 26 Jan 2023 04:11:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 899E36B0072; Thu, 26 Jan 2023 04:11:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 713668E0001; Thu, 26 Jan 2023 04:11:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5D7476B0071 for ; Thu, 26 Jan 2023 04:11:02 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 34CE7C049A for ; Thu, 26 Jan 2023 09:11:02 +0000 (UTC) X-FDA: 80396380764.07.E888B92 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id EAEF716001C for ; Thu, 26 Jan 2023 09:10:59 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a6WAJyoM; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674724260; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NFWqhe5CaI3Y4DkU4U0LIcVEjrvTHeUR9u8mATKM8YY=; b=3YU5AECEReJnVnH7ImqASOwNIYGJNOmMzvmY55p4Ldu8w1lP5QAG6s63B6Q+d0DaMygRnF Ns8uHsRkcfFRBEd8j93B1/skYYwomemfFXt09KF0lJi1oD/eAFwUG3rDGCmklIGWaZVavo a10FCY1I+Z6FguO3/leh9zKpT9ibkXw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a6WAJyoM; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674724260; a=rsa-sha256; cv=none; b=HJNwOfHEZ+ldDaibdRuCRaHv/ZAcU7QxVxt2UcNvB1AHTw8ifN/38ibbT7npIQpB5hbeAu 4Uoj9wf1KkfCkw2uvX87bR2w0lM4K0lOIrDhwKxjU9buhnZhqsd9pi8SBovzm1UYaqzt1P LS+gX60Q3jMj5ZcrlrSrHDc8qE1pg2E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674724259; 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=NFWqhe5CaI3Y4DkU4U0LIcVEjrvTHeUR9u8mATKM8YY=; b=a6WAJyoM0LsnD2alakX+f1Vl9uss+ElMp4n7dda1GRqjv3+yN6IsHldBhZ4RKnpgCEtqgi bpFWl/Kv0humcxfKuSpNQNPSEQoIQwT6UmIK9+HA9Z3nCeQ2iKUCxcjapvpZ1WH/dAXmSx qDjX2+9UOqA5yMnvUpqO4+PRjCr8T7o= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-524-LWcp4R4rO5u7SM-RqwWSPQ-1; Thu, 26 Jan 2023 04:10:58 -0500 X-MC-Unique: LWcp4R4rO5u7SM-RqwWSPQ-1 Received: by mail-wr1-f71.google.com with SMTP id k11-20020adfe3cb000000b002be503e7f28so148801wrm.2 for ; Thu, 26 Jan 2023 01:10:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NFWqhe5CaI3Y4DkU4U0LIcVEjrvTHeUR9u8mATKM8YY=; b=TFPmjtcUcXaIfc8pcd+NwhYW2TK+zLkisxMLoxOpYqNB0ooHfqviTaD4ZpRO1wtpUo gbsuBTNT6ZuD7FNo6OgCIyHtNJ6eW8wu5LmZzcdQwpGiuZtkM+Wp4OS8qg8aYBt4IuRR 8f20Hq4Z1q9rLHN/wPnQELmIO8OsTLSEeI582zqFqavW3XgykkUe8/YfJMsITahmH6im t5eBLzour7itTV7FpWGRFAKQA2ObE5SE4YFiu4irBy+1YcrMHjtnVJZIffGg+Sq8KYLq l6d1pB87xQ1f7ajvRJWdKhcWdFxoQmcC2lZSVj5uoQOyArTkpIdQ8jvbJTAH69De7ozI HNEA== X-Gm-Message-State: AFqh2kpRHiGlcrOZfmf3Cq4TFbV3hwKZhYM/46YE037UnrKYry0dfLzN Ecjz6VDNNms0kjWf6kmKb67Ar23SOtlejWvS50MlIzjb2tqsbPQAV2ieWsMUvRRe4HtICcwZGqy 07FgGfI3Fleo= X-Received: by 2002:a05:6000:1e0f:b0:2be:449:11b5 with SMTP id bj15-20020a0560001e0f00b002be044911b5mr30112952wrb.69.1674724256931; Thu, 26 Jan 2023 01:10:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXvAgjSpMOkRDcJvGFXJfuOF6E4R1EKAbv5nzUXnHOHUryhF+kxveL93+cCZwh2WArPppymm0g== X-Received: by 2002:a05:6000:1e0f:b0:2be:449:11b5 with SMTP id bj15-20020a0560001e0f00b002be044911b5mr30112931wrb.69.1674724256644; Thu, 26 Jan 2023 01:10:56 -0800 (PST) Received: from ?IPV6:2a09:80c0:192:0:5dac:bf3d:c41:c3e7? ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with ESMTPSA id p12-20020a05600c468c00b003dc22ee5a2bsm1874602wmo.39.2023.01.26.01.10.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Jan 2023 01:10:56 -0800 (PST) Message-ID: <6e9b29af-b6e8-77c3-edec-d1713b76ce89@redhat.com> Date: Thu, 26 Jan 2023 10:10:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: A mapcount riddle To: James Houghton , Mike Kravetz Cc: linux-mm@kvack.org, Naoya Horiguchi , David Rientjes , Michal Hocko , Matthew Wilcox , Peter Xu , Muchun Song References: From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: EAEF716001C X-Stat-Signature: 8zm17kx686f1ndh7f474rh1o9gm8jjmx X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674724259-971662 X-HE-Meta: U2FsdGVkX18pmUI/s/p8+ZWQcbNa8toXSDP7R3QivZd52Cm9iv//3lyJGbi8jIIUmAmiJzwvVIqlrPpAHkn79FE3IJ4i4Q+oCw/mr9orwCsnUio4fYNdGXd4CUj69+IoEO04oO7aT4Ha6l8I1Z8eF+ptN4MHgx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ZvNRQxepgVWzne835kz0IrdatALYzS8NGVfQyK1l/QJGe8EbGSczJr57+ZY+gB/n4HN7AoFcc2oxT15Dd9bxQxr8tNPrYKRqt7Rm99FkJletve8bU 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 25.01.23 16:26, James Houghton wrote: >> At first thought this seems bad. However, I believe this has been the >> behavior since hugetlb PMD sharing was introduced in 2006 and I am >> unaware of any reported issues. I did a audit of code looking at >> mapcount. In addition to the above issue with smaps, there appears >> to be an issue with 'migrate_pages' where shared pages could be migrated >> without appropriate privilege. >> >> /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */ >> if (flags & (MPOL_MF_MOVE_ALL) || >> (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) { >> if (isolate_hugetlb(page, qp->pagelist) && >> (flags & MPOL_MF_STRICT)) >> /* >> * Failed to isolate page but allow migrating pages >> * which have been queued. >> */ >> ret = 1; >> } > > This isn't the exact same problem you're fixing Mike, but I want to > point out a related problem. > > This is the generic-mm-equivalent of the hugetlb code above: > > static int migrate_page_add(struct page *page, struct list_head > *pagelist, unsigned long flags) > { > struct page *head = compound_head(page); > /* > * Avoid migrating a page that is shared with others. > */ > if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(head) == 1) { > if (!isolate_lru_page(head)) { > list_add_tail(&head->lru, pagelist); > mod_node_page_state(page_pgdat(head), > NR_ISOLATED_ANON + page_is_file_lru(head), > thp_nr_pages(head)); > ... > } > > If you have a partially PTE-mapped THP, page_mapcount(head) will not > accurately determine if a page is mapped in multiple VMAs or not (it > only tells you how many times the head page is mapped). This came up in the context of [1]. As the new naming (and my naming change) suggestion implies, this is a pure estimate of the numbers of sharers. The check is not supposed to be accurate and it can't be. [1] https://lkml.kernel.org/r/20230124012210.13963-1-vishal.moola@gmail.com > > For example... > 1) You could have the THP PMD-mapped in one VMA, and then one tail > page of the THP can be mapped in another. page_mapcount(head) will be > 1. > 2) You could have two VMAs map two separate tail pages of the THP, in > which case page_mapcount(head) will be 0. > > I bring this up because we have the same problem with HugeTLB > high-granularity mapping. The more I think of it, the nicer it would be to just keep maintaining a single mapcount+ref for the hugetlb case ... -- Thanks, David / dhildenb