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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,UNPARSEABLE_RELAY 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 AF327ECE560 for ; Mon, 17 Sep 2018 20:01:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 62C3D214C5 for ; Mon, 17 Sep 2018 20:01:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62C3D214C5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728440AbeIRBaE (ORCPT ); Mon, 17 Sep 2018 21:30:04 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:58902 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbeIRBaD (ORCPT ); Mon, 17 Sep 2018 21:30:03 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R961e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07467;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0T8v7cEI_1537214459; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T8v7cEI_1537214459) by smtp.aliyun-inc.com(127.0.0.1); Tue, 18 Sep 2018 04:01:03 +0800 Subject: Re: [RFC v10 PATCH 0/3] mm: zap pages with read mmap_sem in munmap for large mapping To: Matthew Wilcox Cc: mhocko@kernel.org, ldufour@linux.vnet.ibm.com, vbabka@suse.cz, kirill@shutemov.name, akpm@linux-foundation.org, dave.hansen@intel.com, oleg@redhat.com, srikar@linux.vnet.ibm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1536957299-43536-1-git-send-email-yang.shi@linux.alibaba.com> <20180915101042.GD31572@bombadil.infradead.org> From: Yang Shi Message-ID: Date: Mon, 17 Sep 2018 13:00:58 -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: <20180915101042.GD31572@bombadil.infradead.org> 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 9/15/18 3:10 AM, Matthew Wilcox wrote: > On Sat, Sep 15, 2018 at 04:34:56AM +0800, Yang Shi wrote: >> Regression and performance data: >> Did the below regression test with setting thresh to 4K manually in the code: >> * Full LTP >> * Trinity (munmap/all vm syscalls) >> * Stress-ng: mmap/mmapfork/mmapfixed/mmapaddr/mmapmany/vm >> * mm-tests: kernbench, phpbench, sysbench-mariadb, will-it-scale >> * vm-scalability >> >> With the patches, exclusive mmap_sem hold time when munmap a 80GB address >> space on a machine with 32 cores of E5-2680 @ 2.70GHz dropped to us level >> from second. >> >> munmap_test-15002 [008] 594.380138: funcgraph_entry: | __vm_munmap { >> munmap_test-15002 [008] 594.380146: funcgraph_entry: !2485684 us | unmap_region(); >> munmap_test-15002 [008] 596.865836: funcgraph_exit: !2485692 us | } >> >> Here the excution time of unmap_region() is used to evaluate the time of >> holding read mmap_sem, then the remaining time is used with holding >> exclusive lock. > Something I've been wondering about for a while is whether we should "sort" > the readers together. ie if the acquirers look like this: > > A write > B read > C read > D write > E read > F read > G write > > then we should grant the lock to A, BCEF, D, G rather than A, BC, D, EF, G. I'm not sure how much this can help to the real world workload. Typically, there are multi threads to contend for one mmap_sem. So, they are trying to read/write the same address space. There might be dependency or synchronization among them. Sorting read together might break the dependency? Thanks, Yang > A quick way to test this is in __rwsem_down_read_failed_common do > something like: > > - if (list_empty(&sem->wait_list)) > + if (list_empty(&sem->wait_list)) { > adjustment += RWSEM_WAITING_BIAS; > + list_add(&waiter.list, &sem->wait_list); > + } else { > + struct rwsem_waiter *first = list_first_entry(&sem->wait_list, > + struct rwsem_waiter, list); > + if (first.type == RWSEM_WAITING_FOR_READ) > + list_add(&waiter.list, &sem->wait_list); > + else > + list_add_tail(&waiter.list, &sem->wait_list); > + } > - list_add_tail(&waiter.list, &sem->wait_list); > > It'd be interesting to know if this makes any difference with your tests. > > (this isn't perfect, of course; it'll fail to sort readers together if there's > a writer at the head of the queue; eg: > > A write > B write > C read > D write > E read > F write > G read > > but it won't do any worse than we have at the moment).