Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1881685ybg; Thu, 24 Oct 2019 01:21:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUYIikCNg9aaZLtQDa+DDb1Yh52SAhbua6mtULfbgQpK/c4agbzvEu9CgzVJ/94n6WczCu X-Received: by 2002:a17:906:2d68:: with SMTP id f8mr14020202eji.71.1571905291700; Thu, 24 Oct 2019 01:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571905291; cv=none; d=google.com; s=arc-20160816; b=gpTWnM8SvgOaNf6zRZ8bYn1Kajk+HfY758eWUYI6qWI/aclHkErnabn+bSmNJYhiBU g6ZZoiTZqpa5sLZIzokHavIApKGhGeZzAoIx4/sqaspRhmQaz+dS1Qk2CYRKsutG18yi trSEyyEdSyItjUdncWllAeCCVNqQvX8sgE5TbU4EDYqJ8zM6pRfsIgvWLfBpTBWpB4A6 ny3gVzwUWDUf27nA7ouCXdQOgnu/g2plNhTwDKyXHy9HiZDbxTCxBPlIa8Io7YfdcJZZ wcP5Ijb4k5VUILVhxlNLUOLOuFkGMvXbhxPt6CrKLcGQQwydhYqOLtAj0SrR/nPlJvSb 0JOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=bLOeRegScxhTo21AtmK06hIjstn4+fKsrBfso2mO7d4=; b=yiWYxUwc1g/WhgNpww2zi2jBm8Qi0gZPyWnhlxREaI4uElN/5yeUOGHZbIXSRXWSIL z+ORiUbQvM4KJu0O6+hW8seHWm9vf19J8iCzU84Q6koHuWgpZOqMEq1CaBvz5U2pi3Ak TkMg2grcwcEdtdNX//f51Gir6wvD1egJK8/urZCpid9Mu1JpS0Wc+8aiLOpqIujNluML oiURJiDdAGeFnxj0JpUHJFequZA+TExMXfrhJ6xihByEynxdQ4x/tsyNfZ+7cg0jWCKV kqt0z8eXoPDwUxeEi95jinjRzTxzM8Nw86Ud39z1Nr2xLoLoUM+LRU0RxTQDNKDl2kUU 39XA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gz25si6481023ejb.81.2019.10.24.01.21.06; Thu, 24 Oct 2019 01:21:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726652AbfJWRCS (ORCPT + 99 others); Wed, 23 Oct 2019 13:02:18 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:45255 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbfJWRCS (ORCPT ); Wed, 23 Oct 2019 13:02:18 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R821e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07487;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Tg.HetG_1571850128; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tg.HetG_1571850128) by smtp.aliyun-inc.com(127.0.0.1); Thu, 24 Oct 2019 01:02:10 +0800 Subject: Re: [PATCH] mm: thp: handle page cache THP correctly in PageTransCompoundMap To: Hugh Dickins Cc: aarcange@redhat.com, kirill.shutemov@linux.intel.com, gavin.dg@linux.alibaba.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1571769577-89735-1-git-send-email-yang.shi@linux.alibaba.com> <4ea5d015-19cb-d5d9-42f7-d1319d8de7c4@linux.alibaba.com> From: Yang Shi Message-ID: Date: Wed, 23 Oct 2019 10:02:06 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/22/19 6:31 PM, Hugh Dickins wrote: > On Tue, 22 Oct 2019, Yang Shi wrote: >> On 10/22/19 3:27 PM, Hugh Dickins wrote: >>> I completely agree that the current PageTransCompoundMap() is wrong. >>> >>> A fix for that is one of many patches I've not yet got to upstreaming. >>> Comparing yours and mine, I'm worried by your use of PageDoubleMap(), >>> because really that's a flag for anon THP, and not properly supported >>> on shmem (or now I suppose file) THP - I forget the details, is it >>> that it sometimes gets set, but never cleared? Generally, we just >>> don't refer to PageDoubleMap() on shmem THPs (but there may be >>> exceptions: sorting out the THP mapcount maze, and eliminating >>> PageDoubleMap(), is one of my long-held ambitions, not yet reached). >>> >>> Here's the patch I've been carrying, but it's from earlier, so I >>> should warn that I've done no more than build-testing it on 5.4, >>> and I'm too far away from these issues at the moment to be able to >>> make a good judgement or argue for it - I hope you and others can >>> decide which patch is the better. I should also add that we're >>> barely using PageTransCompoundMap() at all: at best it can only >>> give a heuristic guess as to whether the page is pmd-mapped in >>> any particular case, and we preferred to take forward the KVM >>> patches we posted back in April 2016, plumbing hva down to where >>> it's needed - though of course those are somewhat different now. >> Thanks for catching this. I was definitely thinking about using >> compount_mapcount instead of DoubleMap flag when I was working the patch. I >> just simply thought it would change less file by using DoubleMap flag but I >> didn't notice it was kind of unbalanced for file THP. >> >> With the unbalanced DoubleMap flag, it sounds better to use >> compound_mapcount. > Yes: no doubt PageDoubleMap could be fixed on shmem+file, but I have no > interest in doing that, because it's just unnecessary overhead for them. > (They have their own overhead, of subpage mapcounting for pmd: which is > something to eliminate and unify with anon when I get around to it.) It might be worth fixing the unbalance since mlock depends on this flag too. There should be a little bit overhead when handling PTE rmap remove since we have to iterate every subpage to check if _mapcount is same with compound_mapcount or not in order to clear DoubleMap flag. It is easy to handle this when the last PMD map is gone. > >> Thanks for sharing your patch, I'm going to rework v2 by using >> compound_mapcount. Do you mind I might steal your patch? > Please do! One less for me to worry about, thanks. > >> I'm supposed we'd better fix this bug regardless of whether you would like to >> move forward your KVM patches. > Absolutely. There remain a few other uses of PageTransCompoundMap > anyway, and I really wanted this outright mm fix to go in before > re-submitting AndresLC's KVM patch (I'll ask a KVM-savvy colleague > to take that over, Cc'ing you, once the mm end is correct). Thanks. > > Hugh