Received: by 10.223.164.221 with SMTP id h29csp2267506wrb; Thu, 2 Nov 2017 08:19:07 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RaNzGZUkUCFcawtSjxO7kUc5rjqz06cKdIY4ufCaNfxM5ZvEruaZwHflZ8Zf1McRxSPxeV X-Received: by 10.99.66.130 with SMTP id p124mr4028250pga.0.1509635947790; Thu, 02 Nov 2017 08:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509635947; cv=none; d=google.com; s=arc-20160816; b=Zi+nFF8plvhPIcMPqfLnNiltcpsWt2E+RhyVU2PRNB8dTdEHQECeMWybtlngAdEaVi l7k/QzkUo9fWwmN7in0VO3oqNa9F1gd5lMj0ZzYEzGb//IYmdYFUdBsX9Lu7dXbF9/4Q STSn3NGWHvwu72xiTcbZj1zcH+tm4P5deMjUVfaUBehiAQ0KtlRwFWi4JxTQt68eH2ro v1a1saVqWrOMV1EmcSc8CTr08L1IB+Dkm5C9NPQXeONG5NxtFowouNzJpZ0ItWL8Vphi QhIH1Wt5IEAtvxHvlQCoQZj9XAe5Biu08cRDcDc1Orj8Z6Agely0X4sM77zOLMlQoh3R upFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject:arc-authentication-results; bh=iIeBGQheqh1OH1MVzV0vE+AKVzIEGkJPsZImw3UByuE=; b=WEMam3xLopkJD2uSwo/TBXk6RmKevwBM/9uzkvLZjxZ2kQRmG8aokCHPTlgVg5kFdb 6pjH8P/FHImfGLRh/Ee7SVyjVVu+T/UA4dkK+AuFYgtYb6LOCAnLEdEf975ZZEJcOgvS UkdlQJVPq7cjgtbOGouJ/9jKBxerma4wv7fNoCP2T7NEDMyw1sGjfWeKm42IU/5dM3W9 BnBpzgoE8RN9xk+3qWafl9Ao+8O5LYYLGR1Q61U2TK66Th8b7HT4TQ/Kn/Q/kUFLHhSx GXPw7WR9rpU8bC/0MGPdWoh873DOQ4lateM/pe7pCE/aYSFC515srycOQ5fF7VnkuNTh S73Q== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c25si3705182pgn.808.2017.11.02.08.18.53; Thu, 02 Nov 2017 08:19:07 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933724AbdKBPQ4 (ORCPT + 97 others); Thu, 2 Nov 2017 11:16:56 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46972 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933418AbdKBPQz (ORCPT ); Thu, 2 Nov 2017 11:16:55 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA2FFrG5008383 for ; Thu, 2 Nov 2017 11:16:54 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e047dpppb-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 02 Nov 2017 11:16:54 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 2 Nov 2017 15:16:51 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 2 Nov 2017 15:16:45 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA2FGile27984020; Thu, 2 Nov 2017 15:16:44 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A92C211C050; Thu, 2 Nov 2017 15:11:49 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E4C6911C04A; Thu, 2 Nov 2017 15:11:47 +0000 (GMT) Received: from [9.101.4.33] (unknown [9.101.4.33]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 2 Nov 2017 15:11:47 +0000 (GMT) Subject: Re: [PATCH v5 07/22] mm: Protect VMA modifications using VMA sequence count To: Andrea Arcangeli Cc: paulmck@linux.vnet.ibm.com, peterz@infradead.org, akpm@linux-foundation.org, kirill@shutemov.name, ak@linux.intel.com, mhocko@kernel.org, dave@stgolabs.net, jack@suse.cz, Matthew Wilcox , benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , Alexei Starovoitov , linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org References: <1507729966-10660-1-git-send-email-ldufour@linux.vnet.ibm.com> <1507729966-10660-8-git-send-email-ldufour@linux.vnet.ibm.com> <20171026101833.GF563@redhat.com> From: Laurent Dufour Date: Thu, 2 Nov 2017 16:16:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171026101833.GF563@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17110215-0016-0000-0000-000004FCCE95 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110215-0017-0000-0000-000028385F88 Message-Id: <2cbea37c-c2a7-bfd4-4528-fd273b210e29@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-02_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1711020190 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrea, Thanks for reviewing this series, and sorry for the late answer, I took few days off... On 26/10/2017 12:18, Andrea Arcangeli wrote: > Hello Laurent, > > Message-ID: <7ca80231-fe02-a3a7-84bc-ce81690ea051@intel.com> shows > significant slowdown even for brk/malloc ops both single and > multi threaded. > > The single threaded case I think is the most important because it has > zero chance of getting back any benefit later during page faults. > > Could you check if: > > 1. it's possible change vm_write_begin to be a noop if mm->mm_count is > <= 1? Hint: clone() will run single threaded so there's no way it can run > in the middle of a being/end critical section (clone could set an > MMF flag to possibly keep the sequence counter activated if a child > thread exits and mm_count drops to 1 while the other cpu is in the > middle of a critical section in the other thread). This sounds to be a good idea, I'll dig on that. The major risk here is to have a thread calling vm_*_begin() with mm->mm_count > 1 and later calling vm_*_end() with mm->mm_count <= 1, but as you mentioned we should find a way to work around this. > > 2. Same thing with RCU freeing of vmas. Wouldn't it be nicer if RCU > freeing happened only once a MMF flag is set? That will at least > reduce the risk of temporary memory waste until the next RCU grace > period. The read of the MMF will scale fine. Of course to allow > point 1 and 2 then the page fault should also take the mmap_sem > until the MMF flag is set. > I think we could also deal with the mm->mm_count value here, if there is only one thread, no need to postpone the VMA's free operation. Isn't it ? Also, if mm->mm_count <= 1, there is no need to try the speculative path. > Could you also investigate a much bigger change: I wonder if it's > possible to drop the sequence number entirely from the vma and stop > using sequence numbers entirely (which is likely the source of the > single threaded regression in point 1 that may explain the report in > the above message-id), and just call the vma rbtree lookup once again > and check that everything is still the same in the vma and the PT lock > obtained is still a match to finish the anon page fault and fill the > pte? That's an interesting idea. The big deal here would be to detect that the VMA has been touched in our back, but there are not so much VMA's fields involved in the speculative path so that sounds reasonable. The other point is to identify the impact of the vma rbtree lookup, it's also a known order, but there is the vma_srcu's lock involved. > > Then of course we also need to add a method to the read-write > semaphore so it tells us if there's already one user holding the read > mmap_sem and we're the second one. If we're the second one (or more > than second) only then we should skip taking the down_read mmap_sem. > Even a multithreaded app won't ever skip taking the mmap_sem until > there's sign of runtime contention, and it won't have to run the way > more expensive sequence number-less revalidation during page faults, > unless we get an immediate scalability payoff because we already know > the mmap_sem is already contended and there are multiple nested > threads in the page fault handler of the same mm. The problem is that we may have a thread entering the page fault path, seeing that the mmap_sem is free, grab it and continue processing the page fault. Then another thread is entering mprotect or any other mm service which grab the mmap_sem and it will be blocked until the page fault is done. The idea with the speculative page fault is also to not block the other thread which may need to grab the mmap_sem. > > Perhaps we'd need something more advanced than a > down_read_trylock_if_not_hold() (which has to guaranteed not to write > to any cacheline) and we'll have to count the per-thread exponential > backoff of mmap_sem frequency, but starting with > down_read_trylock_if_not_hold() would be good I think. > > This is not how the current patch works, the current patch uses a > sequence number because it pretends to go lockless always and in turn > has to slow down all vma updates fast paths or the revalidation > slowsdown performance for page fault too much (as it always > revalidates). > > I think it would be much better to go speculative only when there's > "detected" runtime contention on the mmap_sem with > down_read_trylock_if_not_hold() and that will make the revalidation > cost not an issue to worry about because normally we won't have to > revalidate the vma at all during page fault. In turn by making the > revalidation more expensive by starting a vma rbtree lookup from > scratch, we can drop the sequence number entirely and that should > simplify the patch tremendously because all vm_write_begin/end would > disappear from the patch and in turn the mmap/brk slowdown measured by > the message-id above, should disappear as well. As I mentioned above, I'm not sure about checking the lock contention when entering the page fault path, checking for the mm->mm_count or a dedicated mm flags should be enough, but removing the sequence lock would be a very good simplification. I'll dig further here, and come back soon. Thanks a lot, Laurent. From 1582314980086105856@xxx Thu Oct 26 10:19:16 +0000 2017 X-GM-THRID: 1580970013752612139 X-Gmail-Labels: Inbox,Category Forums