Received: by 10.213.65.68 with SMTP id h4csp1215422imn; Wed, 28 Mar 2018 23:55:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx49tdOUVV0i45mWDgDAqzecHse/yDvzRIvn2et6PKcQLWaDWD9clXm62QlklD1pzhUUg8Nof X-Received: by 2002:a17:902:1e5:: with SMTP id b92-v6mr7035385plb.78.1522306543212; Wed, 28 Mar 2018 23:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522306543; cv=none; d=google.com; s=arc-20160816; b=JwFIeE+88K4GX5fDppPR1NVyIbsLUtMA4Yg7z53kbdp1mog3wegn0eOfbSZDVmehk1 f12Ul3FnIepWE8d25cWlYpWn0/oKmuWHkPNrNWR0QDe48qkl2n+D0IB1m8eG9VRsHGoK s8rN7jJZOr8RL5tDZoNvWjd9UHXnk8eKGdCsDg2uQukswENHJpv5jXSBrlsmuUbOcYeU TmZttHJ1AkF41Ohw5rTMM+8D4hXvmH8KKPimmxE3OGJNdIoICdvxsglypHojLDHSDRTZ PtzEqNuotb4uVz2wepTPemZ5iAXQ//lkLSj47Jy5pVAP+lfmrnWSxCOmTJsgJLY4bGWu Iclw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=z0Ci4/IBlR4xy1mmF5s5NpANnuryDcpKb9nfeso5yDc=; b=X3dTFpnKm0V1t18CiMu+8gG5bl/dBBjCIaF8A/sYBVr5dehjuhZD75O8B+rxO+SmY2 hQAXtkqRN+CuNsA8Wd/glWpC9JNHStk0o4IqfWGKu9LLOwoaEuEdjFJQbXDIifHti8X0 K2Skx/qXN/1NI6AP55R2aTB1FNT7+ud8N7fUumek3cFo+9nVL/nyMNJFk40Wf9B0ii2n i78d6XDAlRl4UJ0aXu55mqLBAUPvOuL3AP8UO4EyjLbVkCeF1y7UkIeaDK9vtakgfrPK wPdGo15HV3W6I6fA5egRVqQc0Dxie9Vcm5RdxWcZABMIX3gGv81M4CD26TwQk2V1SuD5 0rmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=CD2gTQpE; 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 s189si1686839pgb.126.2018.03.28.23.55.28; Wed, 28 Mar 2018 23:55:43 -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=CD2gTQpE; 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 S1751150AbeC2Gye (ORCPT + 99 others); Thu, 29 Mar 2018 02:54:34 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36176 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750707AbeC2Gyd (ORCPT ); Thu, 29 Mar 2018 02:54:33 -0400 Received: by mail-pg0-f67.google.com with SMTP id 201so2493340pgg.3 for ; Wed, 28 Mar 2018 23:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z0Ci4/IBlR4xy1mmF5s5NpANnuryDcpKb9nfeso5yDc=; b=CD2gTQpEnPXs/piqEffz+y/+xaSwI/sgPHI0hkPeK8rSy6g/L6tk/cbRQj5W2zdJGq wRmTxJfsF2MhrKjOHMqnPd+JZZf/lvlDXaeZsPXv5w/BCLk3qenEqz5IcKfFL6ugwdY8 ayJk1eAVfl0GwvGelXHLctRYkMiodXa0PfOagMfPp4qqO6NyBfyWUBaM8XPExlfEqWCk /djkTKiCfyHneaeNJMVZUxFvbrvd/JhupgFNz8kSAeUa7BLQfSfliFb06/zoyPCKLl3u uD/ywYv/2B+vu6N/Ir0g6LTQ+l9BsjKz7k3K4JlT5l333YQJ1yMU0ERjOAA10lcv14Kj XY4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=z0Ci4/IBlR4xy1mmF5s5NpANnuryDcpKb9nfeso5yDc=; b=XFaFWYNemLR12AgZfrZVwx6tK6l/Mi9FIgKTQn4tXIfDy6/IOWQ3Bqp0UD8C/BKwQI OmlfJoYv7YmPFz7uDPd6rowO6bceYorpdvDD1CCyIhFMf8AQcA81WLCDlLgx8acikf6e F1SZ445vEbQliDuluD4SvOFAFFvXEucEutPoZdBpgg2TifguuYXrR0jfWUS5d8DpmXpp 5DRoC/sP/DZckMs03Jwj/q2wTBY78yDlv5loD+wquNDHn92mtziE6HV7RM90RRAErrjW ZM70qz/4slAePMojXWp+SiE57/FggC6m20bXz462/erMWF51nYRp6luDqfCN9L+NKJ7I sxmQ== X-Gm-Message-State: AElRT7G+C4Ed59E92F9WX9ukq9aS1NIvKZld0s6NLFQDHU69vAUvFzcU rzlGshEcts3keFbLjpch4o4Vqhf0 X-Received: by 10.99.166.10 with SMTP id t10mr4669726pge.357.1522306472394; Wed, 28 Mar 2018 23:54:32 -0700 (PDT) Received: from bbox-2.seo.corp.google.com ([2401:fa00:d:0:7630:de9:f6f2:276f]) by smtp.gmail.com with ESMTPSA id y15sm10392640pfb.37.2018.03.28.23.54.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Mar 2018 23:54:31 -0700 (PDT) From: Minchan Kim To: LKML Cc: Minchan Kim , Joe Perches , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Greg Kroah-Hartman , Martijn Coenen Subject: [PATCH v5] ANDROID: binder: change down_write to down_read Date: Thu, 29 Mar 2018 15:54:24 +0900 Message-Id: <20180329065424.203172-1-minchan@kernel.org> X-Mailer: git-send-email 2.17.0.rc1.321.gba9d0f2565-goog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: Joe Perches Cc: Arve Hjønnevåg Cc: Todd Kjos Cc: Greg Kroah-Hartman Reviewed-by: Martijn Coenen Signed-off-by: Minchan Kim --- From v4: * Fix typo and VM flags clear handling - Joe From v3: * Fix typo From v2: * Fix vma->flag setting - Arve From v1: * remove WARN_ON_ONCE - Greg * add reviewed-by - Martijn Martijn, I took your LGTM of v1 as Reviewed-by. If you don't like it or want to change it to acked-by, please, tell me. drivers/android/binder.c | 4 +++- drivers/android/binder_alloc.c | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 764b63a5aade..bb63e3b54e0c 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -4722,7 +4722,9 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma) failure_string = "bad vm_flags"; goto err_bad_arg; } - vma->vm_flags = (vma->vm_flags | VM_DONTCOPY) & ~VM_MAYWRITE; + vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP; + vma->vm_flags &= ~VM_MAYWRITE; + vma->vm_ops = &binder_vm_ops; vma->vm_private_data = proc; diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 5a426c877dfb..4f382d51def1 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -219,7 +219,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, mm = alloc->vma_vm_mm; if (mm) { - down_write(&mm->mmap_sem); + down_read(&mm->mmap_sem); vma = alloc->vma; } @@ -288,7 +288,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, /* vm_insert_page does not seem to increment the refcount */ } if (mm) { - up_write(&mm->mmap_sem); + up_read(&mm->mmap_sem); mmput(mm); } return 0; @@ -321,7 +321,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, } err_no_vma: if (mm) { - up_write(&mm->mmap_sem); + up_read(&mm->mmap_sem); mmput(mm); } return vma ? -ENOMEM : -ESRCH; -- 2.17.0.rc1.321.gba9d0f2565-goog