[IEEE 2014 4th IEEE International Conference on Information Science and Technology (ICIST) -...

4
Conflict Types and Probabilities in Stochastic TM-Programs* Miroslav Popovic and Ilija Basicevic Faculty of Technical Sciences University of Novi Sad Trg Dositeja Obradovica 6, 21000 Novi Sad, Serbia {miroslav.popovic, ilija.basicevic}@rt-rk.com * This work is partially supported by Serbian Ministry of Education and Science Grant #32031 to M. Popovic. Abstract - Transactional Memory (TM) is an attractive concurrency control mechanism that should deliver much better performance than locks in case when transaction conflicts are rare. But, if the probability of conflicts is high, TM program performance may be very poor. Therefore, when engineering mission critical systems, we need to be able to calculate conflict probabilities. In this paper we study a class of stochastic TM programs for processing groups of transactions on a set of shared t-variables, e.g. bank accounts. Individual transactions are selecting variables they are operating on uniformly at random. We identify and define various types of conflicts among transactions that may arise in such circumstances. We also show how to calculate probabilities of various types of conflicts on some simple examples of groups of transactions sharing one or two t-variables. Our work is still in progress, but the results shown here are affirmative for the approach we use, and they stimulate further research towards more general analysis of this class of TM programs. Index Terms - Parallel Programming, Transactional Memory, Parallelism, Conflict types, Probabilities. I. INTRODUCTION Twenty years after the seminal work of Herlihy and Moss [1], Transactional Memory (TM) [2], [3], [4] is finally being recognized and embraced by industry. The vision of pioneers is finally being materialized in the form of novel TM-enabled multicores like Intel Haswell [5] and IBM Blue Gene [6]. The emergence of these brand new TM-enabled multicores has been preceded with an intensive theoretical research on TM correctness [3], [4], liveness [7], and programming language level semantics [8], [9], [10], which seems to be culminating in what would be a theoretical foundation of contemporary TM-based systems. Looking from current prospective it seems that the main reason for the TM success are the two main advantages of TM over traditional locks. Firstly, by providing higher level abstraction and means for program building blocks composition, TM makes parallel and distributed programming easier and more productive. Secondly, by optimistically allowing transactions to execute in parallel without any locking, and symmetrical unlocking, TM aims to enable more parallelism than locks, and thus deliver better performance than locks. The first advantage seems to be taken for granted by most researchers and is seldom questioned in the literature. On the other hand, when considering system performance, some researchers use metrics other than parallelism, such as algorithm complexity and throughput [11] or number of task schedules [12]. Alternatively, as Agrawal [13], we advocate using parallelism as the prime measure of system performance, and in our previous work we proposed the work-span methodology for estimating parallelism of TM programs [14]. In contrast to the first TM advantage, the second advantage is often doubted, and rightly so, because TM performance gains are realistic only if the transaction conflict probability is low. In case when the transaction conflict probability is high, system performance may be very poor, and it may be the case that using locks may be more advantageous. Therefore calculating both parallelism and transaction conflict probability is of paramount importance. Once the conflict probability is known, the system may either rely on TM or back off to locks. Continuing our previous work, in this paper we study a class of stochastic TM programs for processing groups of transactions on a set of shared t-variables, e.g. bank accounts. We identify and define various types of conflicts among transactions that may arise in such circumstances. We also show how to calculate probabilities of various types of conflicts on some simple examples of groups of transactions sharing one or two t-variables. The rest of the paper is organized as follows. Next section introduces various types of conflicts. Section III presents our analysis for groups of transactions sharing one or two t- variables. Due to the limited space in this paper, proofs of two propositions in Subsection III.C are left as exercises to the reader. Section IV presents the experimental results and Section V concludes the paper. II. PRELIMINARIES ____________________________________ 978-1-4799-4808-6 /14/$31.00 ©2014 IEEE

Transcript of [IEEE 2014 4th IEEE International Conference on Information Science and Technology (ICIST) -...

Page 1: [IEEE 2014 4th IEEE International Conference on Information Science and Technology (ICIST) - Shenzhen, China (2014.4.26-2014.4.28)] 2014 4th IEEE International Conference on Information

Conflict Types and Probabilities in Stochastic TM-Programs*

Miroslav Popovic and Ilija Basicevic

Faculty of Technical Sciences University of Novi Sad

Trg Dositeja Obradovica 6, 21000 Novi Sad, Serbia {miroslav.popovic, ilija.basicevic}@rt-rk.com

* This work is partially supported by Serbian Ministry of Education and Science Grant #32031 to M. Popovic.

Abstract - Transactional Memory (TM) is an attractive concurrency control mechanism that should deliver much better performance than locks in case when transaction conflicts are rare. But, if the probability of conflicts is high, TM program performance may be very poor. Therefore, when engineering mission critical systems, we need to be able to calculate conflict probabilities. In this paper we study a class of stochastic TM programs for processing groups of transactions on a set of shared t-variables, e.g. bank accounts. Individual transactions are selecting variables they are operating on uniformly at random. We identify and define various types of conflicts among transactions that may arise in such circumstances. We also show how to calculate probabilities of various types of conflicts on some simple examples of groups of transactions sharing one or two t-variables. Our work is still in progress, but the results shown here are affirmative for the approach we use, and they stimulate further research towards more general analysis of this class of TM programs. Index Terms - Parallel Programming, Transactional Memory, Parallelism, Conflict types, Probabilities.

I. INTRODUCTION

Twenty years after the seminal work of Herlihy and Moss [1], Transactional Memory (TM) [2], [3], [4] is finally being recognized and embraced by industry. The vision of pioneers is finally being materialized in the form of novel TM-enabled multicores like Intel Haswell [5] and IBM Blue Gene [6]. The emergence of these brand new TM-enabled multicores has been preceded with an intensive theoretical research on TM correctness [3], [4], liveness [7], and programming language level semantics [8], [9], [10], which seems to be culminating in what would be a theoretical foundation of contemporary TM-based systems. Looking from current prospective it seems that the main reason for the TM success are the two main advantages of TM over traditional locks. Firstly, by providing higher level abstraction and means for program building blocks composition, TM makes parallel and distributed programming easier and more productive.

Secondly, by optimistically allowing transactions to execute in parallel without any locking, and symmetrical unlocking, TM aims to enable more parallelism than locks, and thus deliver better performance than locks. The first advantage seems to be taken for granted by most researchers and is seldom questioned in the literature. On the other hand, when considering system performance, some researchers use metrics other than parallelism, such as algorithm complexity and throughput [11] or number of task schedules [12]. Alternatively, as Agrawal [13], we advocate using parallelism as the prime measure of system performance, and in our previous work we proposed the work-span methodology for estimating parallelism of TM programs [14]. In contrast to the first TM advantage, the second advantage is often doubted, and rightly so, because TM performance gains are realistic only if the transaction conflict probability is low. In case when the transaction conflict probability is high, system performance may be very poor, and it may be the case that using locks may be more advantageous. Therefore calculating both parallelism and transaction conflict probability is of paramount importance. Once the conflict probability is known, the system may either rely on TM or back off to locks. Continuing our previous work, in this paper we study a class of stochastic TM programs for processing groups of transactions on a set of shared t-variables, e.g. bank accounts. We identify and define various types of conflicts among transactions that may arise in such circumstances. We also show how to calculate probabilities of various types of conflicts on some simple examples of groups of transactions sharing one or two t-variables. The rest of the paper is organized as follows. Next section introduces various types of conflicts. Section III presents our analysis for groups of transactions sharing one or two t-variables. Due to the limited space in this paper, proofs of two propositions in Subsection III.C are left as exercises to the reader. Section IV presents the experimental results and Section V concludes the paper.

II. PRELIMINARIES

____________________________________978-1-4799-4808-6 /14/$31.00 ©2014 IEEE

Page 2: [IEEE 2014 4th IEEE International Conference on Information Science and Technology (ICIST) - Shenzhen, China (2014.4.26-2014.4.28)] 2014 4th IEEE International Conference on Information

Let T be a group of n transactions T = {t1, t2, …, tn} and V be a set of m t-variables V = {v1, v2, …, vm} shared by transactions in T, such that each transaction ti uniformly at random selects a subset Vi of the set V. Note that Vi may be any subset, including the empty set. ASSUMPTION 1. If a t-variable vk in V is selected by at least two transactions in T, then at least one of them is defining vk (i.e. writing to it). REMARK 1. Besides being realistic, this assumption is introduced to simplify further analysis without losing generality. A brief clarification seems appropriate at this point. Obviously if a t-variable vk is selected by a single transaction ti, there cannot be any transaction conflicts involving vk, no matter how ti operates on vk (ti may read form and/or write to vk). On the other hand, if a t-variable vk is selected by more transactions, clearly there will be a conflict among them over vk, if at least one of them is defining vk (i.e. writing to it). Assumption 1 assumes this case. Generality is not lost because any selection of t-variables in V by transactions in T such that a t-variable vk is selected only to be used (read), may be reduced to a selection satisfying Assumption 1 by deleting the t-variable vk from all the subsets Vi containing it.

state

conflict-free conflict

partial entire

mediumminimal maximal

Fig. 1 Transaction conflict types. After transactions in T make their selections of t-variables in V, the group of transactions T may either enter the state conflict-free or the state conflict, see Fig. 1. If the conflict involves all the transactions in T, it is classified as the entire conflict (global conflict), otherwise as the partial conflict (local conflict). The entire conflict may be either the minimal entire conflict, the medium entire conflict, or the maximal entire conflict – or more briefly the minimal conflict, the medium conflict, and the maximal conflict. Informally, the maximal conflict means that each transaction in T is in conflict with all the remaining transactions in T, the minimal conflict involves all the transactions in T, but with the minimum of individual conflicts, whereas the medium conflict is in between these two kinds of conflicts. DEFINITION 1. A group of transactions T is in the state conflict-free if not a single t-variable in V is selected by more

than one transaction in T. Otherwise, a group of transactions T is in the state conflict. DEFINITION 2. A conflict is the partial conflict if not all the transactions in T are involved in it. Otherwise it is the entire conflict. DEFINITION 3. An entire conflict is the minimal conflict if each transaction in T has a single conflict with some other transaction when n � 4 and n is even, or a single transaction in T has two conflicts (with some other two transactions) and remaining transactions in T have a single conflict (with some other transaction) when n � 3 and n is odd. REMARK 2. In case when n � 4 and n is even, a group of transactions T may be partitioned into pairs of conflicting transactions {ti, tj} such that ti is in conflict with tj, and vice versa, but neither of them are in conflict with any other transaction in T. In case when n � 3 and n is odd, there must a conflicting transaction trio { ti, tj, tk} such that { ti, tk } and {tj, tk } are conflicting pairs, whereas {ti, tj} is not a conflicting pair, and that T \ { ti, tj, tk } may be partitioned into conflicting pairs (if n � 5). DEFINITION 4. An entire conflict is the maximal conflict if each transaction ti in T is in conflict with all the remaining transactions in T, which means that Vi Vj is not the empty set for all j such that j i. DEFINITION 5. An entire conflict is the medium conflict if it is neither the minimal conflict nor the maximal conflict. Let Pnc be the probability that a group of transactions T is in the state conflict-free, Pc the probability that T is in the state conflict, Ppar that conflict is partial, Pent that conflict is entire, Pmin that conflict is minimal, Pmd, that conflict is medium, and Pmax that conflict is maximal. It may be useful to establish the following proposition. PROPOSITION 1. For a group of transactions T sharing a set of t-variables V, the following conditions must hold:

11

1

maxmin =++++

=++=+

PPPPPPPP

PP

mdparnc

entparnc

cnc (1)

PROOF. Follows directly from Definitions 1 to 5. Finally, it seems appropriate clarifying possible states of a group of transactions T for n = 1, and n = 2. For the case n = 1, T is always conflict-free, because a transaction cannot be in conflict with itself, whereas for the case n = 2, T is either in the state conflict-free or in the state maximal conflict. REMARK 3. Since parallelism depends on conflicts, and conflicts have certain probabilities, parallelism, �, becomes a discrete random variable, whose probability distribution function F� may be determined. Once F� is known, important statistical measures, like the expected value (mean) E(�) and the disturbance (deviation) D(�), may be calculated.

III. EXAMPLES OF ANALYSIS

In this section we demonstrate how theory from the previous section and our previous work [14] may be used to analyze conflicts and parallelism for a given group of transactions T randomly sharing a set of variables V. In

Page 3: [IEEE 2014 4th IEEE International Conference on Information Science and Technology (ICIST) - Shenzhen, China (2014.4.26-2014.4.28)] 2014 4th IEEE International Conference on Information

particular we analyze groups of 2 or 3 transactions (i.e. n = 2 or 3), where all the transactions in the same group randomly select either one or two t-variables from V (more precisely, all transactions select one t-variable or all transactions select two t-variables).

A. Two Transactions, One T-Variable

Let T be a group of n = 2 transactions T = {t1, t2} and V be a set of m t-variables V = {v1, v2, …, vm}, m � 1, shared by transactions in T. Assume that each transaction in T uniformly at random selects a single t-variable, such that V1 = {vi} and V2 = {vj} where vi, vj ∈ V. The probabilities of possible states are as follows. PROPOSITION 2. The probability that the group of transactions T in this case will enter the state conflict-free is the following:

mmPnc

1−= (2)

PROOF. All possible selections are variations with repetition of m t-variables on two places (one place for each transaction). There are m2 such selections. Among them, selections without conflicts are variations without repetition of m t-variables on two places. There are m(m–1) such selections. Therefore: Pnc = m(m–1)/m2 = (m–1)/m, so (2) is true. PROPOSITION 3. The probability that the group of transactions T in this case will enter the state conflict is the following:

mPc

1= (3)

PROOF. All possible selections are the same as in Proposition 2, and there are m2 of them. Selections creating conflicts are those where both transactions select the same t-variable. Since there are m t-variables, there are m such selections. Therefore: Pc = m / m2 = 1 / m, so (3) is true. Obviously, Pnc converges to 1, whereas Pc converges to 0, when the number of t-variables, m, grows to infinity. Based on [14], we get that parallelism is � = 2 for the state conflict-free and � = 1 for the state conflict. Thus E(�) is equal to:

mm�E 12)( −= (4)

E(�) converges to 2 when m grows to infinity.

B. Three Transactions, One T-Variable

Let T be a group of n = 3 transactions T = {t1, t2, t3} and V be a set of m t-variables V = {v1, v2, …, vm}, m � 2, shared by transactions in T. Assume that each transaction in T uniformly at random selects a single t-variable, such that V1 = {va}, V2 = {vb}, V3 = {vc}, where va, vb, vc ∈ V. The probabilities of possible states are as follows. PROPOSITION 4. The probability that the group of transactions T in this case will enter the state conflict-free is the following:

2)2)(1(

mmmPnc

−−= (5)

PROOF. All possible selections are variations with repetition of m t-variables on three places (one place for each transaction). There are m3 such selections. Among them, selections without conflicts are variations without repetition of m t-variables on three places. There are: m(m–1)(m–2) such selections. Therefore, Pnc = m(m–1)(m–2) / m3 , and finally we get Pnc = (m–1)(m–2) / m2 , so (5) is true. PROPOSITION 5. The probability that the group of transactions T in this case will enter the state maximal conflict is the following:

2max1

mP = (6)

PROOF. All possible selections are the same as in Proposition 4, and there are m3 of them. Selections creating conflicts are those where all three transactions select the same t-variable. Since there are m t-variables, there are m such selections. Therefore, Pc = m / m3 = 1 / m2, so (6) is true. PROPOSITION 6. The probability that the group of transactions T in this case will enter the state partial conflict is the following:

2)1(3

mmPpar

−= (7)

PROOF. All possible selections are the same as in Proposition 4, and there are m3 of them. Selections creating conflicts are counted as follows. Assume that a pair of transactions, say {t1, t2}, selected the same variable, thus they are in conflict. Since there are m t-variables, there are m such selections. The third transaction, say t3, selects any of the remaining (m–1) t-variables in order to stay out of the conflict. This makes m(m–1) selections so far. Further on, a non-conflicting transaction may be any of the three transactions in T (the remaining two are in conflict). So, the total number of selections leading to a partial conflict is equal to 3m(m–1). Thus, Ppar = 3m(m–1) / m3 = 3(m–1) / m2, so (7) is true. Obviously, Pnc converges to 1, whereas both Ppar, and Pmax converge to 0, when the number of t-variables, m, grows to infinity. Based on [14], we get that parallelism is � = 3 for the state conflict-free, � = 3/2 for the state partial conflict, and � = 1 for the state maximal conflict. Thus E(�) is equal to:

2

2

25

293

)(m

mm�E

+−= (8)

E(�) converges to 3 when m grows to infinity.

C. Two Transactions, Two T-Variables

Let T be a group of n = 2 transactions T = {t1, t2} and V be a set of m t-variables V = {v1, v2, …, vm}, m � 3, shared by transactions in T. Assume that each transaction in T uniformly at random selects two t-variables, such that V1 = {va, vb}, V2 =

Page 4: [IEEE 2014 4th IEEE International Conference on Information Science and Technology (ICIST) - Shenzhen, China (2014.4.26-2014.4.28)] 2014 4th IEEE International Conference on Information

{vc, vd}, where va, vb, vc, vd ∈ V. The probabilities of possible states are as follows. PROPOSITION 7. The probability that the group of transactions T in this case will enter the state conflict-free is the following:

)1()3)(2(

−−−=

mmmmPnc

(9)

PROPOSITION 8. The probability that the group of transactions T in this case will enter the state conflict is the following:

)1(64

−−=

mmmPc

(10)

Obviously, Pnc converges to 1, whereas Pc converges to 0, when the number of t-variables, m, grows to infinity. Based on [14], we get that parallelism is � = 2 for the state conflict-free and � = 1 for the state conflict. Thus E(�) is equal to:

)1()33(2)(

2

−+−=

mmmm�E (11)

E(�) converges to 2 when m grows to infinity.

IV. EXPERIMENTAL RESULTS

We experimentally validated theoretical results from the previous section. Here we present only the selected results, in particular the validation results for propositions 3 and 8, see Fig. 2. Dashed curves P1 and P3 are conflict probabilities according to eq. (3) and (10), respectively. Solid curves P2 and P4 are the corresponding conflict probabilities measured by averaging results of 100 experiments, each. Obviously, both solid curves follow the corresponding dashed curves closely, thus indicating that theoretical results are correct.

Fig. 2 Calculated and measured conflict probabilities related to (3) and (10).

V. CONCLUSIONS

In this paper, we define various types of conflicts for stochastic TM programs, which comprise a group of transactions sharing a set of t-variables, such that transactions are selecting their t-variables uniformly at random. We then show, by examples of groups of two, or three, transactions sharing one, or two, t-variables, how conflict probabilities may be calculated. Further on, by calculating parallelism and probability for all possible states, which a group of transactions may enter, we determine the parallelism probability distribution function, and expected parallelism. Our future work will address more general analysis of this class of TM programs.

REFERENCES [1] M. Herlihy and J.E.B. Moss, “Transactional memory: architectural

support for lockfree data structures”, In Proc. of the 20th Annual International Symposium on Computer Architecture, ISCA ’93, ACM, New York, NY, pp. 289–300, 1993.

[2] T. Harris, J.R. Larus, and R. Rajwar, Transactional Memory, 2nd edition, Morgan and Claypool, 2010.

[3] R. Guerraoui and M. Kapalka, Principles of Transactional Memory, Morgan and Claypool, 2010.

[4] S. Doherty, L. Groves, V. Luchangco, and M. Moir, “Towards Formally Specifying and Verifying Transactional Memory”, Formal Aspects of Computing, March 2012, pp. 1-31, 2012.

[5] J. Reinders, “Transactional Synchronization in Haswell”, URL= http://software.intel.com/enus/blogs/2012/02/07/transactional-synchronization-inhaswell, 2013.

[6] R.A. Haring, M. Ohmacht, T.W. Fox, M.K. Gschwind, D.L. Satterfield, K. Sugavanam, P.W. Coteus, P. Heidelberger, M.A. Blumrich, R.W. Wisniewski, A. Gara, G.L.-T. Chiu, P.A. Boyle, N.H. Chist, and C. Kim, “The IBM Blue Gene/Q Compute Chip”, IEEE Micro, vol. 32, no. 2, pp. 48-60, 2012.

[7] V. Bushkov, R. Guerraoui, and M. Kapalka, “On the Liveness of Transactional Memory”, In Proc. of the 2012 ACM Symposium on Principles of Distributed Computing (Madeira, Portugal, July 16-18, 2012), PODC '12, pp. 9-18, 2012.

[8] V. Menon, S. Balensiefer, T. Shpeisman, A.R. Adl-Tabatabai, R.L. Hudson, B. Saha, and A. Welc, “Practical weak-atomicity semantics for java stm”, In Proc. of the Symposium on Parallelism in Algorithms and Architectures, SPAA’08, pp. 314–325, 2008.

[9] K.F. Moore and D. Grossman, “High-level small-step operational semantics for transactions”, In Proc. of the Symposium on Principles of Programming Languages, POPL’08, pp. 51–62, 2008.

[10] M. Abadi, A. Birrell, T. Harris, and M. Isard, “Semantics of transactional memory and automatic mutual exclusion”, ACM Transactions on Programming Languages and Systems, vol. 33, no. 1, pp. 2:1-2:50, 2011.

[11] N. Diegues, and J. Cachopo, “Exploring parallelism in transactional workloads”, Technical Report. RT/16/2012, INESC-ID Lisbon, June 2012, 2012.

[12] V. Gramoli, P. Kuznetsov, and S. Ravi, “Sharing a Sequential Data Structure: Correctness Definition and Correctness Analysis”, The Fourth Workshop on the Theory of Transactional Memory, WTTM’12, URL=http://lpd.epfl.ch/gramoli/wttm4, 2012.

[13] K. Agrawal, J.T. Fineman, J. Sukha, “Nested parallelism in transactional memory”, In Proceedings of the 13th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, ACM Press, New York, USA, pp. 163-174, 2008.

[14] M. Popovic, I. Basicevic, M. Djukic, and N. Cetic, “Estimating Parallelism of Transactional Memory Programs”, In Proceedings of the 3rd IEEE International Conference on Information Science and Technology, Yangzhou, Jiangsu, China, pp. 437-443, 2013.