Received: by 10.213.65.68 with SMTP id h4csp2162407imn; Thu, 29 Mar 2018 19:42:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ohmyQFZ5SEwfEpxH31uoa/RTGsH4/dDC767SqDTlt6e0eE4Xge7Jx5+rvczXbcSG8fFSo X-Received: by 2002:a17:902:43a4:: with SMTP id j33-v6mr11252276pld.260.1522377740675; Thu, 29 Mar 2018 19:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522377740; cv=none; d=google.com; s=arc-20160816; b=pJf2GvPIj23AwjOUBTywc465noTH1FzPGbM7PiTE8d+STaS9nvOBpGh+yvwJxJPTz1 MBnfVWnttQVc2w1Z8zAg3ok+XZpdcrumVKfcI8zDD5I059tIB9EIg7zfjKZNoOOQxEmR rApCN+kwiiCNNnMPi+cS/OnTi5Vsii7xBi5l4olN1HxHdGK3IZr+AI5RXHQcQgNXlWFQ OMKr0D6gfzVjQ5qk1G348op7uqGuKQUqlDBR8v6DqpAHb9jmU/cSWHOm8ATQVlGURi+2 FnsUEg8kV0yLkvu9Kl91rrTX6eqsCRrNLrLE/S/wofDVbhZjKzgX3VTP7XlDxYWCl9TK zdTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=HzAey2PHgNMBGX9QwaYWa0PqhpwmTWRs5M4wyJYzsK8=; b=kGCiIPZ5J5CP+1BlF+ySs9UpEyM0t/Qav0UeSwswmJdqJwjDGp6lUpRr3vyUEF7fOE kwZcPUoZhCtWnV+iQyPtlf5KidicApX6Xq10mPMXZAR0Cbje6D9FUmpXWIFRRJT06gYG gaALOAZFczap/Nwq1XVDgcXtjOoEoERoavThS3oyEvBgbx6bPipW3MSYP7WZDramblkf jmzb6zfE0FhMWrunYEMOkAwXUS9+m9JmojbTcZCaGzOmCyAc6yPB9ylvtI0Wh54LtfO4 NPvmuTLEUqTSh4fAtDTX45YEJmU8O6TeGP5yeoT88qgAGJWwDuAdkQPWqJoYwCakF2xB sEdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=JYt06ujF; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1-v6si2987586plk.577.2018.03.29.19.42.05; Thu, 29 Mar 2018 19:42:20 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=JYt06ujF; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752289AbeC3Ck4 (ORCPT + 99 others); Thu, 29 Mar 2018 22:40:56 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:42577 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751209AbeC3Ckz (ORCPT ); Thu, 29 Mar 2018 22:40:55 -0400 Received: by mail-pf0-f181.google.com with SMTP id a16so4544749pfn.9 for ; Thu, 29 Mar 2018 19:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HzAey2PHgNMBGX9QwaYWa0PqhpwmTWRs5M4wyJYzsK8=; b=JYt06ujFkoghDzhnUY7D05xlpKgTcglE+Tx+jBC2OeIAclHPVcKnSrb6Ot5GqdR0DG VCmrwrMv5f+eaNxvrU9Y2lholVe2QdKYVb7LzwGZk73yCBbbXLYFwUZhdyW0TULFHsLQ S8IGjaewKHDUYFkWpRiZYsJ7t09jFoNk87gsNeku1hzCZaBhn10CHpbuAp8r2lAXFUqq l8OhSzWIeIGeDV/38g+bWTw/uxnrWo3xv/NyercuZRGe7+DHb+RV3hJe90g8bHnEyTRc nOeIBhhhln00hQ1lSzmfBXICGg6GYzuIGr6TAmvUvKIR5VuuRHUOU+WS+tfhfgO6ezXc w5qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=HzAey2PHgNMBGX9QwaYWa0PqhpwmTWRs5M4wyJYzsK8=; b=DdFIW0RZNmQUsliirh1n8qBeVgPj4rUzUYFevNyg6LPuNPDtswgGI+HKGzGKyskDjG 1rHLMA2/f7P1LFsPAkknbuXdVGeH/hq+TczIVSw542+JhXwZoNv4cAfHn5hNo4rbIIWU 9kbYBwxfIrbZedrZ2IMvJRLotRmCMwos8flp004Gcsx4FX56p1nMwWEhBiVVv+hJGxtf 1mqYcXDMFiGPFFuq7ftIrEaPhh18w2cRqCGDZIpsxvospXfgfbQSMVg7e9nz0bB97Kxi y03/k4kw9HSAdi45EwSC68MBoiNzpfoXXasoR6GGZlcVgWBsQ+KS2Yy8YtLdkYJnhvCU /eVQ== X-Gm-Message-State: AElRT7ErCFxVDvGJBlASA55V8ghi+LDUkS5LIXjrpGfdiOstrvL7sUBU 2F+21llihiQ55kZniXggQn4= X-Received: by 10.101.97.169 with SMTP id i9mr7153964pgv.31.1522377654128; Thu, 29 Mar 2018 19:40:54 -0700 (PDT) Received: from rodete-desktop-imager.corp.google.com ([2401:fa00:d:0:7630:de9:f6f2:276f]) by smtp.gmail.com with ESMTPSA id p8sm12426688pgf.75.2018.03.29.19.40.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Mar 2018 19:40:52 -0700 (PDT) Date: Fri, 30 Mar 2018 11:40:48 +0900 From: Minchan Kim To: Ganesh Mahendran Cc: LKML , Joe Perches , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Greg Kroah-Hartman , Martijn Coenen , Peter Zijlstra , Ingo Molnar Subject: Re: [PATCH v5] ANDROID: binder: change down_write to down_read Message-ID: <20180330024048.GC255979@rodete-desktop-imager.corp.google.com> References: <20180329065424.203172-1-minchan@kernel.org> <20180330012921.GB255979@rodete-desktop-imager.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 30, 2018 at 09:39:03AM +0800, Ganesh Mahendran wrote: > 2018-03-30 9:29 GMT+08:00 Minchan Kim : > > Hi Ganesh, > > > > On Fri, Mar 30, 2018 at 09:21:55AM +0800, Ganesh Mahendran wrote: > >> 2018-03-29 14:54 GMT+08:00 Minchan Kim : > >> > binder_update_page_range needs down_write of mmap_sem because > >> > vm_insert_page need to change vma->vm_flags to VM_MIXEDMAP unless > >> > it is set. However, when I profile binder working, it seems > >> > every binder buffers should be mapped in advance by binder_mmap. > >> > It means we could set VM_MIXEDMAP in binder_mmap time which is > >> > already hold a mmap_sem as down_write so binder_update_page_range > >> > doesn't need to hold a mmap_sem as down_write. > >> > > >> > Android suffers from mmap_sem contention so let's reduce mmap_sem > >> > down_write. > >> > >> Hi, Minchan: > >> > >> It seems there is performance regression of this patch. > > > > You mean "This patch aims for solving performance regression" not "This patch > > makes performance regression"? > > After applying this patch in our devices, app launch time increases > about 15% in average. > "This patch makes performance regression", yes, from the results, it > is like this. > > I will do more test of this patch. Thanks for the testing. Every apps increases time? I will appreciate if you confirm the problem again. I guess the reason is currently rw_semaphore's preferrence for writer at up_write so If binder uses down_read instead of down_write, binder should compete other down_read callers at wake up time from up_write and could lose wakeup chance if it is low priority. Anyway, I think it's abuse of using down_write to get lock holding asap where it's down_read enough. I guess there is tradeoff based on binder's priority. If we go to the speculative page faults or range-lock instad of mmap_sem, the situation would be much improved. Anyway, currently, I have no idea to overcome such prioriy inversion problem from rw_semaphore and I believe generally changing from down_read to down_write is good thing to prevent contention. Ccing maintainers.